Skip to content

Instantly share code, notes, and snippets.

@olen2006
Created May 9, 2022 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olen2006/46ab7b3bb705fcfa36f7f4072827fa6a to your computer and use it in GitHub Desktop.
Save olen2006/46ab7b3bb705fcfa36f7f4072827fa6a to your computer and use it in GitHub Desktop.
Play to deploy nexus
---
#Deploy Nexus
- name: Install java and net-tools
hosts: nexus
tasks:
- name: Update yum repo and cache
yum: update_cache=yes name=* state=latest lock_timeout=3600
- name: Install Java 8
yum:
name: java-1.8.0
state: latest
- name: Download and unpack Nexus
hosts: nexus
tasks:
- name: Check nexus folder stats
stat:
path: /opt/nexus
register: stat_result
- name: Download Nexus
get_url:
url: https://download.sonatype.com/nexus/3/latest-unix.tar.gz
dest: /opt/
register: download_result
- name: Unarchive nexus installer
unarchive:
src: "{{ download_result.dest }}"
dest: /opt/
remote_src: yes
when: not stat_result.stat.exists
- name: Find nexus folder
find:
paths: /opt
pattern: "nexus-*"
file_type: directory
register: find_result
- name: Rename nexus folder
shell: mv {{ find_result.files[0].path}} /opt/nexus
when: not stat_result.stat.exists
- name: Create nexus user to own nexus folders
hosts: nexus
tasks:
- name: Ensure group nexus exists
group:
name: nexus
state: present
- name: Create nexus user
user:
name: nexus
group: nexus
- name: Make nexus user owner of the nexus folder
file:
path: /opt/nexus
state: directory
owner: nexus
group: nexus
recurse: yes
- name: Make nexus user owner of the sonatype-work folder
file:
path: /opt/sonatype-work
state: directory
owner: nexus
group: nexus
recurse: yes
- name: Start nexus with nexus user
hosts: nexus
become: True
become_user: nexus
tags: nexus
tasks:
- name: Set run_as_user nexus
lineinfile:
path: /opt/nexus/bin/nexus.rc
regexp: '^#run_as_user=""'
line: run_as_user="nexus"
- name: Check with nexus with ps
shell: ps aux | grep "nexus" | grep "java" | grep -v grep
register: nexus_status
ignore_errors: true
- name: Start nexus service
command: /opt/nexus/bin/nexus start
when: not nexus_status.stdout_lines
- name: Verify nexus is running
hosts: nexus
tasks:
- name: Verify nexus with ps
shell: ps aux | grep "nexus" | grep "java" | grep -v grep
register: nexus_status
- debug: msg={{nexus_status}}
- name: Wait one minute
pause:
minutes: 1
- name: Verify with netstat
shell: netstat -plnt
register: app_status
- debug: msg={{app_status}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment