From 49be68b4dbf4edbbb1f5e025b21490faa98a8a04 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Tue, 30 Aug 2022 07:51:10 -0500 Subject: [PATCH] add supervisor role --- roles/supervisor/defaults/main.yaml | 24 ++++++++++ roles/supervisor/handlers/main.yaml | 5 +++ roles/supervisor/tasks/default.yaml | 0 roles/supervisor/tasks/main.yaml | 44 +++++++++++++++++++ .../supervisor/templates/supervisord.conf.j2 | 26 +++++++++++ roles/supervisor/vars/default.yaml | 0 6 files changed, 99 insertions(+) create mode 100644 roles/supervisor/defaults/main.yaml create mode 100644 roles/supervisor/handlers/main.yaml create mode 100644 roles/supervisor/tasks/default.yaml create mode 100644 roles/supervisor/tasks/main.yaml create mode 100644 roles/supervisor/templates/supervisord.conf.j2 create mode 100644 roles/supervisor/vars/default.yaml diff --git a/roles/supervisor/defaults/main.yaml b/roles/supervisor/defaults/main.yaml new file mode 100644 index 0000000..02cea5f --- /dev/null +++ b/roles/supervisor/defaults/main.yaml @@ -0,0 +1,24 @@ +--- +supervisor_package_name: supervisor +supervisor_package_state: present + +supervisor_service_name: supervisor +supervisor_service_state: started +supervisor_service_enabled: true + +supervisor_etc_path: /etc/supervisor +supervisor_config_path: "{{ supervisor_etc_path }}/supervisord.conf" +supervisor_config_owner: root +supervisor_config_group: root +supervisor_config_mode: "0644" + +supervisor_unix_http_server_socket_file: /var/run/supervisor.sock +supervisor_unix_http_server_socket_chmod: "0700" + +supervisor_supervisord_logfile: /var/log/supervisor/supervisord.log +supervisor_supervisord_pidfile: /var/run/supervisord.pid +supervisor_supervisord_childlogdir: /var/log/supervisor + +supervisor_supervisorctl_serverurl: "unix://{{ supervisor_unix_http_server_socket_file }}" + +supervisor_include_files: /etc/supervisor/conf.d/*.conf diff --git a/roles/supervisor/handlers/main.yaml b/roles/supervisor/handlers/main.yaml new file mode 100644 index 0000000..b1933a7 --- /dev/null +++ b/roles/supervisor/handlers/main.yaml @@ -0,0 +1,5 @@ +--- +- name: restart supervisor + service: + name: "{{ supervisor_service_name }}" + state: restarted diff --git a/roles/supervisor/tasks/default.yaml b/roles/supervisor/tasks/default.yaml new file mode 100644 index 0000000..e69de29 diff --git a/roles/supervisor/tasks/main.yaml b/roles/supervisor/tasks/main.yaml new file mode 100644 index 0000000..8f05dc6 --- /dev/null +++ b/roles/supervisor/tasks/main.yaml @@ -0,0 +1,44 @@ +--- +- name: gather os specific variables + include_vars: "{{ lookup('first_found', possible_files) }}" + vars: + possible_files: + files: + - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml" + - "{{ ansible_distribution }}.yaml" + - "{{ ansible_os_family }}.yaml" + - "default.yaml" + paths: + - vars + +- name: include os specific tasks + include_tasks: "{{ lookup('first_found', possible_files) }}" + vars: + possible_files: + files: + - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml" + - "{{ ansible_distribution }}.yaml" + - "{{ ansible_os_family }}.yaml" + - "default.yaml" + paths: + - tasks + +- name: install package + package: + name: "{{ supervisor_package_name }}" + state: "{{ supervisor_package_state }}" + +- name: configure + template: + src: supervisord.conf.j2 + dest: "{{ supervisor_config_path }}" + owner: "{{ supervisor_config_owner }}" + group: "{{ supervisor_config_group }}" + mode: "{{ supervisor_config_mode }}" + notify: restart supervisor + +- name: manage service + service: + name: "{{ supervisor_service_name }}" + state: "{{ supervisor_service_state }}" + enabled: "{{ supervisor_service_enabled }}" diff --git a/roles/supervisor/templates/supervisord.conf.j2 b/roles/supervisor/templates/supervisord.conf.j2 new file mode 100644 index 0000000..d33c09d --- /dev/null +++ b/roles/supervisor/templates/supervisord.conf.j2 @@ -0,0 +1,26 @@ +; {{ ansible_managed }} + +[unix_http_server] +{% if supervisor_unix_http_server_socket_file is defined %} +file={{ supervisor_unix_http_server_socket_file }} +{% endif %} +{% if supervisor_unix_http_server_socket_chmod is defined %} +chmod={{ supervisor_unix_http_server_socket_chmod }} +{% endif %} +{% if supervisor_unix_http_server_socket_chown is defined %} +chown={{ supervisor_unix_http_server_socket_chown }} +{% endif %} + +[supervisord] +logfile={{ supervisor_supervisord_logfile }} +pidfile={{ supervisor_supervisord_pidfile }} +childlogdir={{ supervisor_supervisord_childlogdir }} + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl={{ supervisor_supervisorctl_serverurl }} + +[include] +files = {{ supervisor_include_files }} diff --git a/roles/supervisor/vars/default.yaml b/roles/supervisor/vars/default.yaml new file mode 100644 index 0000000..e69de29