commit b19ed9bbfc3f04bb2a39cff36b9c2d459fa04b15 Author: Olivier Navas Date: Fri Jun 24 12:48:55 2022 +0200 Commit initial diff --git a/README.md b/README.md new file mode 100644 index 0000000..066a3f0 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# Role : docker_healthchecks + +## Services fournis + +- main.yml : Installation de healthchecks sur un serveur docker_host + + +## Variables + +Fournir les variables suivantes. Par exemple : + +```yaml +docker_healthchecks_fqdn: healthchecks.local.lan +docker_healthchecks_version: v2.2.1 +docker_healthchecks_data_dir: /data1 +docker_healthchecks_service_id: healthchecks +docker_healthchecks_db: healthchecks +docker_healthchecks_db_user: healthchecks +docker_healthchecks_db_password: motdepassebdd +docker_healthchecks_config_env: + - DB=postgres + - DB_HOST=db + - DB_NAME={{ docker_healthchecks_db }} + - DB_USER={{ docker_healthchecks_db_user }} + - DB_PASSWORD={{ docker_healthchecks_db_password }} + - DB_PORT=5432 + - etc +``` + +| Option | Valeur par défaut | Description | +|---------------------------------|-------------------|--------------------------------------------------------------------------------------------| +| docker_healthchecks_fqdn | | Le fqdn pour accéder à healthchecks | +| docker_healthchecks_version | | Version de l'image healthchecks | +| docker_healthchecks_data_dir | | L'emplacement dans lequel se trouvent les volumes de donnees docker pour le service | +| docker_healthchecks_service_id | | Le nom de service souhaité : conditionne le nommage des dossiers et le routage par traefik | +| docker_healthchecks_db | | Le nom de la base de données | +| docker_healthchecks_db_user | | Le nom du user propriétaire de la base de données | +| docker_healthchecks_db_password | | Le mot de passe du user propriétaire de la base de données | +| docker_healthchecks_config_env | | Une liste de variables d'environnement pour la configuration de healtchecks | + + +## Configuration de healthchecks + +Une part de la configuration de healthchecks se fait dans les variables d'environnement qui lui sont fournies via docker_healthchecks_config_env + +Après le premier démarrage il sera nécessaire de créer un admin, qui pourra poursuivre la configuration depuis l'interface web, avec : +```bash +docker-compose run healthchecks /opt/healthchecks/manage.py createsuperuser +``` diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..d6c2d4b --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +- name: docker-compose-up + shell: | + docker-compose up -d + args: + chdir: /opt/{{ docker_healthchecks_service_id }}/ diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..9af9659 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,14 @@ +- name: docker directory + file: + path: /opt/{{ docker_healthchecks_service_id }}/ + state: directory + +- name: prepare docker-compose.yml + template: + src: "{{ item }}" + dest: /opt/{{ docker_healthchecks_service_id }}/ + with_items: + - docker-compose.yml + notify: docker-compose-up + + diff --git a/templates/docker-compose.yml b/templates/docker-compose.yml new file mode 100644 index 0000000..895fee0 --- /dev/null +++ b/templates/docker-compose.yml @@ -0,0 +1,40 @@ +# {{ ansible_managed }} + +version: '3.1' + +services: + healthchecks: + image: healthchecks/healthchecks:{{ docker_healthchecks_version }} + environment: {{ docker_healthchecks_config_env }} + restart: always + networks: + - traefik + - healthchecks + labels: + - "org.label-schema.group=monitoring" + - "traefik.enable=true" + - "traefik.docker.network=traefik" + - "traefik.http.routers.{{ docker_healthchecks_service_id }}.entrypoints=web" + - "traefik.http.routers.{{ docker_healthchecks_service_id }}.rule=Host(`{{ docker_healthchecks_fqdn }}`)" + - "traefik.http.services.{{ docker_healthchecks_service_id }}.loadbalancer.server.port=8000" + depends_on: + - db + command: bash -c 'uwsgi /opt/healthchecks/docker/uwsgi.ini' + + + db: + image: postgres:13 + volumes: + - {{ docker_healthchecks_data_dir }}/{{ docker_healthchecks_service_id }}/postgresql-data:/var/lib/postgresql/data + environment: + POSTGRES_DB: "{{ docker_healthchecks_db }}" + POSTGRES_USER: "{{ docker_healthchecks_db_user }}" + POSTGRES_PASSWORD: "{{ docker_healthchecks_db_password }}" + networks: + - healthchecks + +networks: + traefik: + external: true + healthchecks: + internal: true