From 777e6721791c458e946ac8267e82fcd1b4b3cd5c Mon Sep 17 00:00:00 2001 From: KsmoinO <99479-KsmoinO1@users.noreply.framagit.org> Date: Mon, 24 May 2021 16:20:54 +0200 Subject: [PATCH] Initial commit --- defaults/main.yaml | 39 +++++++++++++++++++ handlers/main.yml | 5 +++ tasks/main.yml | 66 +++++++++++++++++++++++++++++++++ templates/checks.csv.j2 | 3 ++ templates/incidents.txt.j2 | 3 ++ templates/tinystatus.service.j2 | 9 +++++ templates/tinystatus.sh.j2 | 3 ++ templates/tinystatus.timer.j2 | 9 +++++ 8 files changed, 137 insertions(+) create mode 100644 defaults/main.yaml create mode 100644 handlers/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/checks.csv.j2 create mode 100644 templates/incidents.txt.j2 create mode 100644 templates/tinystatus.service.j2 create mode 100644 templates/tinystatus.sh.j2 create mode 100644 templates/tinystatus.timer.j2 diff --git a/defaults/main.yaml b/defaults/main.yaml new file mode 100644 index 0000000..58e3a44 --- /dev/null +++ b/defaults/main.yaml @@ -0,0 +1,39 @@ +--- + +tinystatus_bindir: /opt/tinystatus +tinystatus_configdir: /etc/tinystatus +tinstatus_gitrepo: https://github.com/bderenzo/tinystatus +tinystatus_webdir: /var/www/html +tinystatus_pagefile: index.html +tinystatus_webuser: nginx +tinystatus_webgrp: nginx +tinystatus_user: nobody +tinystatus_grp: nobody +tinystatus_checks: + - name: Google Website + type: http + code: 200 + host: https://google.com + - name: Google Website (IPv4) + type: http4 + code: 200 + host: https://google.com + - name: Google Website (IPv6) + type: http6 + code: 200 + host: https://google.com + - name: Google 404 + type: http + code: 404 + host: https://google.com/dummy + - name: Google ping + type: ping + code: 0 + host: 8.8.8.8 + - name: Google DNS + type: port + code: 0 + host: 8.8.8.8 53 +tinystatus_incidents: [] +tinystatus_Timer_OnCalendar: "*-*-* *:00/10:00" +tinystatus_RandomizedDelaySec: 300 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..85dc8db --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- + +- name: systemd daemon-reload + systemd: + daemon-reload: yes diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..65afd13 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,66 @@ +--- +- name: Installation des prérequis + yum: + name: + - git + state: present +- name: Clonage du dépôt + git: + repo: "{{ tinstatus_gitrepo }}" + dest: "{{ tinystatus_bindir }}" + force: yes +- name: Mise en place du contectexte selinux + file: + path: "{{ tinystatus_bindir }}/tinystatus" + setype: bin_t +- name: Création du répertoire de configuration + file: + state: directory + path: "{{ tinystatus_configdir }}" + mode: 0555 +- name: Déployment des fichiers de configuration + template: + src: "{{ item }}.j2" + dest: "{{ tinystatus_configdir }}/{{ item }}" + mode: 0444 + loop: + - checks.csv + - incidents.txt +- name: Création du scritp d'éxécution + template: + src: tinystatus.sh.j2 + dest: "{{ tinystatus_bindir }}/tinystatus.sh" + mode: 0555 + setype: bin_t +- name: Création des fichiers systemd + template: + src: "{{ item }}.j2" + dest: "/etc/systemd/system/{{ item }}" + mode: 0644 + loop: + - tinystatus.service + - tinystatus.timer + notify: systemd daemon-reload +- name: Flush handlers + meta: flush_handlers +- name: Création du répertoire de site web pour génération du fichier + file: + state: directory + path: "{{ tinystatus_webdir }}" + owner: "{{ tinystatus_webuser }}" + group: "{{ tinystatus_webgrp }}" + setype: httpd_sys_content_t + mode: u=rx,g=rxs,o=rx +- name: Création du fichier d'index avec les bonnes permissions + file: + path: "{{ tinystatus_webdir }}/{{ tinystatus_pagefile }}" + state: touch + owner: "{{ tinystatus_user }}" + group: "{{ tinystatus_grp }}" + setype: httpd_sys_content_t + mode: 0644 +- name: Active et démarre tinystatus.timer + systemd: + name: tinystatus.timer + enabled: yes + state: started diff --git a/templates/checks.csv.j2 b/templates/checks.csv.j2 new file mode 100644 index 0000000..24c8d89 --- /dev/null +++ b/templates/checks.csv.j2 @@ -0,0 +1,3 @@ +{% for check in tinystatus_checks %} +{{ check.type }}, {{ check.code }}, {{ check.name }}, {{ check.host }} +{% endfor %} diff --git a/templates/incidents.txt.j2 b/templates/incidents.txt.j2 new file mode 100644 index 0000000..c0850f8 --- /dev/null +++ b/templates/incidents.txt.j2 @@ -0,0 +1,3 @@ +{% for incident in tinystatus_incidents %} +{{ incident }} +{% endfor %} diff --git a/templates/tinystatus.service.j2 b/templates/tinystatus.service.j2 new file mode 100644 index 0000000..68c4311 --- /dev/null +++ b/templates/tinystatus.service.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=tinystatus +Documentation={{ tinstatus_gitrepo }} + +[Service] +Type=oneshot +User={{ tinystatus_user }} +ExecStart={{ tinystatus_bindir }}/tinystatus.sh +PrivateTmp=true diff --git a/templates/tinystatus.sh.j2 b/templates/tinystatus.sh.j2 new file mode 100644 index 0000000..1722010 --- /dev/null +++ b/templates/tinystatus.sh.j2 @@ -0,0 +1,3 @@ +#!/bin/bash +# {{ ansible_managed }} +{{ tinystatus_bindir }}/tinystatus {{ tinystatus_configdir }}/checks.csv {{ tinystatus_configdir }}/incidents.txt > {{ tinystatus_webdir }}/{{ tinystatus_pagefile }} diff --git a/templates/tinystatus.timer.j2 b/templates/tinystatus.timer.j2 new file mode 100644 index 0000000..3ae7ac3 --- /dev/null +++ b/templates/tinystatus.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Run tinystatus + +[Timer] +OnCalendar={{ tinystatus_Timer_OnCalendar }} +RandomizedDelaySec={{ tinystatus_RandomizedDelaySec }} + +[Install] +WantedBy=timers.target