Created
April 6, 2023 03:25
-
-
Save kratsg/35737437c162ee27709921f16e124b38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Install supervisord | |
hosts: root | |
gather_facts: true | |
become: false | |
vars: | |
dest_path: /etc/supervisor/supervisord.conf | |
tasks: | |
- name: Check if pyenv exists | |
block: | |
- name: Run command | |
ansible.builtin.command: command -v pyenv | |
register: command | |
changed_when: false | |
always: | |
- name: Debugging pyenv command | |
ansible.builtin.debug: | |
msg: "{{ 'Failed to find pyenv' if command.failed else 'Found pyenv' }}{{ command }}" | |
- name: Get pyenv root | |
ansible.builtin.command: "pyenv root" | |
register: pyenv | |
changed_when: false | |
- name: Get stats of virtualenv | |
ansible.builtin.stat: | |
path: "{{ pyenv.stdout }}" | |
register: p | |
changed_when: false | |
- name: Create virtualenv | |
ansible.builtin.command: | |
cmd: pyenv virtualenv supervisor | |
creates: "{{ pyenv.stdout }}/versions/supervisor" | |
- name: Install supervisor into the supervisor virtualenv | |
ansible.builtin.command: | |
cmd: "$(pyenv root)/versions/supervisor/bin/python -m pip install supervisor multivisor[rpc]" | |
creates: "{{ pyenv.stdout }}/versions/supervisor/bin/supervisord" | |
register: pipinstall | |
- name: Make sure destination dir exists | |
ansible.builtin.file: | |
path: "{{ dest_path | dirname }}" | |
state: directory | |
- name: Create supervisord.conf | |
ansible.builtin.template: | |
src: "supervisord.conf.j2" | |
dest: "{{ dest_path }}" | |
force: true | |
mode: 0644 | |
vars: | |
virtualenv_path: "{{ pyenv.stdout }}/versions/supervisor" | |
changed_when: pipinstall.changed | |
- name: Install init-script | |
ansible.builtin.template: | |
src: "initscript-supervisord_{{ ansible_facts['distribution'] }}.j2" | |
dest: /etc/systemd/system/supervisord.service | |
force: true | |
mode: 0644 | |
vars: | |
virtualenv_path: "{{ pyenv.stdout }}/versions/supervisor" | |
options: "-c {{ dest_path }}" | |
- name: Open 9002 for multivisor | |
ansible.posix.firewalld: | |
port: 9002/tcp | |
permanent: true | |
state: enabled | |
immediate: true | |
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' | |
- name: Start and enable init-script | |
ansible.builtin.systemd: | |
name: supervisord | |
state: started | |
enabled: true | |
daemon_reload: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment