Skip to content

Instantly share code, notes, and snippets.

@kratsg
Created April 6, 2023 04:42
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 kratsg/bbc480d808d5f39f5c86e7fd4eb72d93 to your computer and use it in GitHub Desktop.
Save kratsg/bbc480d808d5f39f5c86e7fd4eb72d93 to your computer and use it in GitHub Desktop.
---
- name: Install supervisord
hosts: root
gather_facts: true
become: false
vars:
dest_path: /etc/supervisor/supervisord.conf
roles:
- role: markosamuli.pyenv
vars:
pyenv_python_versions:
- "3.10.3"
pyenv_global: "3.10.3"
tasks:
- name: Check if pyenv exists
block:
- name: Run command
ansible.builtin.shell: ". $HOME/.profile; command -v pyenv; echo $PATH"
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.shell: ". $HOME/.profile; 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.shell:
cmd: . $HOME/.profile; pyenv virtualenv supervisor
creates: "{{ pyenv.stdout }}/versions/supervisor"
- name: Install supervisor into the supervisor virtualenv
ansible.builtin.shell:
cmd: ". $HOME/.profile; $(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