summaryrefslogtreecommitdiff
path: root/roles/healthchecks
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2020-02-02 01:44:51 -0500
committerThedro Neely <thedroneely@gmail.com>2020-02-02 01:44:51 -0500
commitafbaec650def427987e0caf3a9a852a67d046247 (patch)
tree392ba2d817909a5a1aad4b38d64a344eb077d50d /roles/healthchecks
parent5083913437c4b705907de39aa2e632aca227a436 (diff)
downloadplaybooks-afbaec650def427987e0caf3a9a852a67d046247.tar.gz
playbooks-afbaec650def427987e0caf3a9a852a67d046247.tar.bz2
playbooks-afbaec650def427987e0caf3a9a852a67d046247.zip
roles/healthchecks: Add
Diffstat (limited to 'roles/healthchecks')
-rw-r--r--roles/healthchecks/files/supervisord.conf30
-rw-r--r--roles/healthchecks/main.yml120
2 files changed, 150 insertions, 0 deletions
diff --git a/roles/healthchecks/files/supervisord.conf b/roles/healthchecks/files/supervisord.conf
new file mode 100644
index 0000000..52c3c43
--- /dev/null
+++ b/roles/healthchecks/files/supervisord.conf
@@ -0,0 +1,30 @@
+; Supervisor config file.
+
+[program:healthchecks]
+command=/usr/sbin/uwsgi uwsgi.ini
+directory=/opt/%(program_name)s
+stopasgroup=true
+stdout_logfile=/var/log/%(program_name)s.log
+stdout_logfile_maxbytes=0
+stdout_logfile_backups=0
+redirect_stderr=true
+user=%(program_name)s
+
+[inet_http_server]
+port = 9100
+username = healthchecks
+password = healthchecks
+
+[unix_http_server]
+file=/run/supervisord.sock
+
+[supervisord]
+logfile=/var/log/supervisord.log
+loglevel=info
+user=root
+
+[rpcinterface:supervisor]
+supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
+
+[supervisorctl]
+serverurl=unix:///run/supervisord.sock
diff --git a/roles/healthchecks/main.yml b/roles/healthchecks/main.yml
new file mode 100644
index 0000000..1a0e4b9
--- /dev/null
+++ b/roles/healthchecks/main.yml
@@ -0,0 +1,120 @@
+---
+# target: alpine3.11
+- name: Install Health Checks
+ hosts: healthchecks
+
+ vars_files:
+ - ../variables.yml
+
+ tasks:
+
+ - name: Ensuring group exists
+ group:
+ name: "{{ healthchecks_user }}"
+ state: present
+
+ - name: Creating user and making home directory
+ user:
+ system: yes
+ state: present
+ name: "{{ healthchecks_user }}"
+ groups: "{{ healthchecks_user }}"
+ home: "{{ healthchecks_home }}"
+
+ - name: Installing the required dependencies
+ apk:
+ state: present
+ update_cache: yes
+ name:
+ - musl-dev
+ - postgresql-dev
+ - python3-dev
+ - gcc
+ - git
+ - supervisor
+ - sudo
+ - uwsgi
+ - uwsgi-python
+
+ - block:
+
+ - name: Cloning repository
+ git:
+ repo: "{{ healthchecks_repository }}"
+ dest: "{{ healthchecks_home }}"
+ version: "{{ healthchecks_version }}"
+
+ - name: Setting up python virtual environment
+ shell: python3 -m venv .
+ args:
+ chdir: "{{ healthchecks_home }}"
+ creates: bin/activate
+
+ - name: Pip installing application
+ shell: |
+ . bin/activate
+ pip install -r requirements.txt
+ args:
+ chdir: "{{ healthchecks_home }}"
+
+ - name: Migrating database
+ shell: |
+ . bin/activate
+ ./manage.py migrate
+ args:
+ chdir: "{{ healthchecks_home }}"
+ creates: hc.sqlite
+
+ - name: Setting up application assets
+ blockinfile:
+ path: "{{ healthchecks_home }}/uwsgi.ini"
+ block: |
+ [uwsgi]
+ http-socket = 0.0.0.0:8000
+ enable-threads
+ plugin = python
+ virtualenv = /opt/healthchecks
+ module = hc.wsgi:application
+ static-map = /static=static-collected
+ static-gzip-dir = static-collected/CACHE
+ hook-pre-app = exec:./manage.py collectstatic --noinput
+ hook-pre-app = exec:./manage.py compress --force
+ attach-daemon = ./manage.py sendalerts
+ create: yes
+
+ - name: Setting up application configuration
+ blockinfile:
+ path: "{{ healthchecks_home }}/hc/local_settings.py"
+ block: |
+ SITE_NAME = "Check"
+ DEBUG = False
+ COMPRESS_ENABLED = True
+ REGISTRATION_OPEN = False
+ SECRET = "{{ secret_key }}"
+ create: yes
+
+ become: true
+ become_user: "{{ healthchecks_user }}"
+
+ - name: Copying supervisord config file
+ copy:
+ src: supervisord.conf
+ dest: /etc/supervisord.conf
+ mode: '0644'
+ register: supervisorConfig
+
+ - name: Ensuring supervisord has been started and enabled
+ service:
+ name: supervisord
+ state: started
+ enabled: yes
+
+ - name: Waiting for supervisor to become active
+ wait_for:
+ port: 9100
+
+ - name: Restarting supervisord due to config change
+ service:
+ name: supervisord
+ state: restarted
+ when: supervisorConfig.changed