From c98f9f067554ce03915d77ebb45eb92e71aaf1c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20-=20Le=20Filament?= <theo@le-filament.com>
Date: Mon, 22 Jul 2024 14:17:34 +0200
Subject: [PATCH] style: update linting rules and format code according to them

---
 .yamllint         |   2 +-
 defaults/main.yml |  26 +++----
 handlers/main.yml |   7 +-
 meta/main.yml     |  28 ++++----
 tasks/main.yml    | 171 ++++++++++++++++++++++++----------------------
 5 files changed, 121 insertions(+), 113 deletions(-)

diff --git a/.yamllint b/.yamllint
index fbebdb8..754cd35 100644
--- a/.yamllint
+++ b/.yamllint
@@ -27,7 +27,7 @@ rules:
     indentation:
         level: warning
         indent-sequences: consistent
-        spaces: 4
+        spaces: 2
         check-multi-line-strings: true
     key-duplicates: enable
     line-length: disable
diff --git a/defaults/main.yml b/defaults/main.yml
index 0e02c43..ae4454e 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -4,19 +4,19 @@ nagios_url: "nagios.example.org"
 
 # Webhooks to be triggered daily
 webhooks_to_be_called_daily:
-    - name: Docker Odoo
-      url: gitlab.example.org
-      uri: "/api/v4/projects/xx/ref/REF_NAME/trigger/pipeline?token=TOKEN"
+  - name: Docker Odoo
+    url: gitlab.example.org
+    uri: "/api/v4/projects/xx/ref/REF_NAME/trigger/pipeline?token=TOKEN"
 
 # List of external services to be monitored
 services_to_be_monitored:
-    - name: Webmail
-      period: generic
-      service: https
-      url: mail.example.org
-      uri: /webmail/
-    - name: Certificate IMAP
-      period: daily
-      service: certif
-      url: mail.example.org
-      uri: 993
+  - name: Webmail
+    period: generic
+    service: https
+    url: mail.example.org
+    uri: /webmail/
+  - name: Certificate IMAP
+    period: daily
+    service: certif
+    url: mail.example.org
+    uri: 993
diff --git a/handlers/main.yml b/handlers/main.yml
index e1bb036..f43a35b 100644
--- a/handlers/main.yml
+++ b/handlers/main.yml
@@ -1,6 +1,7 @@
 ---
 
-- name: Restart nagios docker
+- name: "Restart Nagios container"
   community.docker.docker_compose:
-      project_src: /home/docker/nagios/
-      restarted: true
+    project_src: "/home/docker/nagios/"
+    restarted: true
+  listen: "restart nagios container"
diff --git a/meta/main.yml b/meta/main.yml
index 9f02c7e..e76a995 100644
--- a/meta/main.yml
+++ b/meta/main.yml
@@ -1,16 +1,16 @@
 ---
 galaxy_info:
-    author: lefilament
-    description: This role deploys Nagios with Docker to monitor all other defined servers
-    company: Le Filament (https://le-filament.com)
-    license: AGPL-3.0-or-later
-    min_ansible_version: "2.1"
-    platforms:
-        - name: Ubuntu
-          versions:
-              - xenial
-              - bionic
-              - focal
-    galaxy_tags:
-        - nagios
-        - monitoring
+  author: lefilament
+  description: This role deploys Nagios with Docker to monitor all other defined servers
+  company: Le Filament (https://le-filament.com)
+  license: AGPL-3.0-or-later
+  min_ansible_version: "2.1"
+  platforms:
+    - name: Ubuntu
+      versions:
+        - xenial
+        - bionic
+        - focal
+  galaxy_tags:
+    - nagios
+    - monitoring
diff --git a/tasks/main.yml b/tasks/main.yml
index e4631ac..6a36c19 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,103 +1,110 @@
 ---
 
 ## Install Nagios docker
-- name: Create Nagios docker structure on server in /home/docker/nagios
+- name: "Create Nagios docker structure on server in /home/docker/nagios"
   ansible.builtin.file:
-      name: "{{ item }}"
-      state: directory
-      owner: '999'
-      group: '1000'
-      mode: '0755'
+    name: "{{ item }}"
+    state: directory
+    owner: "999"
+    group: "1000"
+    mode: "0755"
   with_items:
-      - /home/docker/nagios/etc/objects
-      - /home/docker/nagios/stylesheets
+    - "/home/docker/nagios/etc/objects"
+    - "/home/docker/nagios/stylesheets"
 
-- name: Copy nagios docker-compose file
+- name: "Copy nagios docker-compose file"
   ansible.builtin.template:
-      src: nagios.yaml.j2
-      dest: /home/docker/nagios/docker-compose.yaml
-      mode: '0644'
-  notify: Restart nagios docker
+    src: "nagios.yaml.j2"
+    dest: "/home/docker/nagios/docker-compose.yaml"
+    mode: "0644"
+  notify: "restart nagios container"
 
-- name: Copy configuration files
+- name: "Copy configuration files"
+  tags:
+    - "nagios_config"
   ansible.builtin.copy:
-      src: "{{ item }}"
-      dest: /home/docker/nagios/etc/{{ item }}
-      mode: '0644'
-      owner: '999'
-      group: '1000'
+    src: "{{ item }}"
+    dest: "/home/docker/nagios/etc/{{ item }}"
+    mode: "0644"
+    owner: "999"
+    group: "1000"
   with_items:
-      - cgi.cfg
-      - nagios.cfg
-      - resource.cfg
-  notify: Restart nagios docker
-  tags: nagios_config
+    - "cgi.cfg"
+    - "nagios.cfg"
+    - "resource.cfg"
+  notify: "restart nagios container"
 
-- name: Copy CSS files
+- name: "Copy CSS files"
+  tags:
+    - "nagios_style"
   ansible.builtin.copy:
-      src: "{{ item }}"
-      dest: /home/docker/nagios/stylesheets/{{ item }}
-      mode: '0644'
-      owner: '999'
-      group: '1000'
+    src: "{{ item }}"
+    dest: "/home/docker/nagios/stylesheets/{{ item }}"
+    mode: "0644"
+    owner: "999"
+    group: "1000"
   with_items:
-      - avail.css
-      - checksanity.css
-      - cmd.css
-      - common.css
-      - config.css
-      - extinfo.css
-      - histogram.css
-      - histogramgraph.css
-      - history.css
-      - jsonquery.css
-      - map.css
-      - map-directive.css
-      - ministatus.css
-      - nag_funcs.css
-      - notifications.css
-      - outages.css
-      - showlog.css
-      - status.css
-      - statusmap.css
-      - summary.css
-      - tac.css
-      - trends.css
-      - trendsgraph.css
-  notify: Restart nagios docker
-  tags: nagios_config
+    - "avail.css"
+    - "checksanity.css"
+    - "cmd.css"
+    - "common.css"
+    - "config.css"
+    - "extinfo.css"
+    - "histogram.css"
+    - "histogramgraph.css"
+    - "history.css"
+    - "jsonquery.css"
+    - "map.css"
+    - "map-directive.css"
+    - "ministatus.css"
+    - "nag_funcs.css"
+    - "notifications.css"
+    - "outages.css"
+    - "showlog.css"
+    - "status.css"
+    - "statusmap.css"
+    - "summary.css"
+    - "tac.css"
+    - "trends.css"
+    - "trendsgraph.css"
+  notify: "restart nagios docker"
 
-- name: Copy objects configuration files
+- name: "Copy objects configuration files"
+  tags:
+    - "nagios_config"
   ansible.builtin.template:
-      src: "{{ item }}.j2"
-      dest: /home/docker/nagios/etc/objects/{{ item }}
-      mode: '0644'
-      owner: '999'
-      group: '1000'
+    src: "{{ item }}.j2"
+    dest: "/home/docker/nagios/etc/objects/{{ item }}"
+    mode: "0644"
+    owner: "999"
+    group: "1000"
   with_items:
-      - vps.cfg
-      - localhost.cfg
-      - templates.cfg
-      - contacts.cfg
-      - commands.cfg
-      - timeperiods.cfg
-  notify: Restart nagios docker
-  tags: nagios_config
+    - "vps.cfg"
+    - "localhost.cfg"
+    - "templates.cfg"
+    - "contacts.cfg"
+    - "commands.cfg"
+    - "timeperiods.cfg"
+  notify: "restart nagios container"
 
-- name: Create apache2 dir on server in /home/docker/nagios
+- name: "Create apache2 dir on server in /home/docker/nagios"
+  tags:
+    - "nagios_webserver"
   ansible.builtin.file:
-      name: /home/docker/nagios/apache2
-      owner: 'root'
-      group: 'root'
-      mode: '0755'
-      state: directory
+    name: "/home/docker/nagios/apache2"
+    owner: "root"
+    group: "root"
+    mode: "0755"
+    state: directory
 
-- name: Install apache2 configuration files
+- name: "Install apache2 configuration files"
+  tags:
+    - "nagios_webserver"
   ansible.builtin.copy:
-      src: "{{ item }}"
-      dest: /home/docker/nagios/apache2/{{ item }}
-      mode: '0644'
+    src: "{{ item }}"
+    dest: "/home/docker/nagios/apache2/{{ item }}"
+    mode: "0644"
   with_items:
-      - 000-default.conf
-      - nagios.conf
-  notify: Restart nagios docker
+    - "000-default.conf"
+    - "nagios.conf"
+  notify: "restart nagios container"
-- 
GitLab