From 001ee75abc647e52df9dc8aede7a3a43f4b29b5c Mon Sep 17 00:00:00 2001 From: Alessandro Rabiti Date: Tue, 27 Aug 2024 16:43:41 +0200 Subject: [PATCH] feat: aggiunta la directory 6_check_ansible-lint --- 2_inventory/20_inventory-test.yaml | 2 +- 2_inventory/22_inventory-test.yaml | 2 +- 2_inventory/23_inventory-test.yaml | 2 +- 2_inventory/24_inventory-test.yaml | 4 +- 6_check_ansible-lint/11_playbook.yaml | 10 +++++ 6_check_ansible-lint/1_playbook.yaml | 11 ++++++ 6_check_ansible-lint/21_inventory.yaml | 23 +++++++++++ 6_check_ansible-lint/2_inventory.yaml | 24 ++++++++++++ 6_check_ansible-lint/README.md | 54 ++++++++++++++++++++++++++ 9 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 6_check_ansible-lint/11_playbook.yaml create mode 100644 6_check_ansible-lint/1_playbook.yaml create mode 100644 6_check_ansible-lint/21_inventory.yaml create mode 100644 6_check_ansible-lint/2_inventory.yaml create mode 100644 6_check_ansible-lint/README.md diff --git a/2_inventory/20_inventory-test.yaml b/2_inventory/20_inventory-test.yaml index da9ee27..0e84151 100644 --- a/2_inventory/20_inventory-test.yaml +++ b/2_inventory/20_inventory-test.yaml @@ -1,4 +1,4 @@ --- all: hosts: - host1test.mydomain.xyz: + host1test.mydomain.xyz: diff --git a/2_inventory/22_inventory-test.yaml b/2_inventory/22_inventory-test.yaml index 61866d6..091935d 100644 --- a/2_inventory/22_inventory-test.yaml +++ b/2_inventory/22_inventory-test.yaml @@ -3,5 +3,5 @@ gruppo_test: hosts: host1test.mydomain.xyz: ansible_host: 127.0.0.2 - host2test.mydomain.xyz: + host2test.mydomain.xyz: ansible_host: 127.0.0.3 diff --git a/2_inventory/23_inventory-test.yaml b/2_inventory/23_inventory-test.yaml index 06c050a..6ea53cf 100644 --- a/2_inventory/23_inventory-test.yaml +++ b/2_inventory/23_inventory-test.yaml @@ -3,7 +3,7 @@ gruppo_test: hosts: host1test.mydomain.xyz: ansible_host: 127.0.0.2 - host2test.mydomain.xyz: + host2test.mydomain.xyz: ansible_host: 127.0.0.3 vars: ansible_user: nobody diff --git a/2_inventory/24_inventory-test.yaml b/2_inventory/24_inventory-test.yaml index ef7b849..3678f64 100644 --- a/2_inventory/24_inventory-test.yaml +++ b/2_inventory/24_inventory-test.yaml @@ -3,7 +3,7 @@ gruppo_test: hosts: host1test.mydomain.xyz: ansible_host: 127.0.0.2 - host2test.mydomain.xyz: + host2test.mydomain.xyz: ansible_host: 127.0.0.3 vars: ansible_user: nobody @@ -12,7 +12,7 @@ gruppo_prod: hosts: host1prod.mydomain.xyz: ansible_host: 127.0.0.4 - host2prod.mydomain.xyz: + host2prod.mydomain.xyz: ansible_host: 127.0.0.5 vars: ansible_user: root diff --git a/6_check_ansible-lint/11_playbook.yaml b/6_check_ansible-lint/11_playbook.yaml new file mode 100644 index 0000000..2f371ce --- /dev/null +++ b/6_check_ansible-lint/11_playbook.yaml @@ -0,0 +1,10 @@ +--- +- name: Stampo a video le facts # nome di questo play, ora gli spazi sono assenti + hosts: all # specifica su quali hosts o gruppi di hosts deve essere eseguito questo play + become: false # utilizza i privilegi di root (default false) + gather_facts: true # raccoglie i dati sull'host (default true) + + tasks: + - name: Stampo a video tutte le facts degli hosts + ansible.builtin.debug: + var: ansible_facts diff --git a/6_check_ansible-lint/1_playbook.yaml b/6_check_ansible-lint/1_playbook.yaml new file mode 100644 index 0000000..18efecf --- /dev/null +++ b/6_check_ansible-lint/1_playbook.yaml @@ -0,0 +1,11 @@ +--- +- name: Stampo a video le facts # nome di questo play, in questa riga c'è qualche spazio di troppo + hosts: all # specifica su quali hosts o gruppi di hosts deve essere eseguito questo play + become: false # utilizza i privilegi di root (default false) + gather_facts: true # raccoglie i dati sull'host (default true) + + tasks: + - name: Stampo a video tutte le facts degli hosts + ansible.builtin.debug: + var: ansible_facts + diff --git a/6_check_ansible-lint/21_inventory.yaml b/6_check_ansible-lint/21_inventory.yaml new file mode 100644 index 0000000..3678f64 --- /dev/null +++ b/6_check_ansible-lint/21_inventory.yaml @@ -0,0 +1,23 @@ +--- +gruppo_test: + hosts: + host1test.mydomain.xyz: + ansible_host: 127.0.0.2 + host2test.mydomain.xyz: + ansible_host: 127.0.0.3 + vars: + ansible_user: nobody + +gruppo_prod: + hosts: + host1prod.mydomain.xyz: + ansible_host: 127.0.0.4 + host2prod.mydomain.xyz: + ansible_host: 127.0.0.5 + vars: + ansible_user: root + +gruppo_all: + children: + gruppo_test: + gruppo_prod: diff --git a/6_check_ansible-lint/2_inventory.yaml b/6_check_ansible-lint/2_inventory.yaml new file mode 100644 index 0000000..49dadf0 --- /dev/null +++ b/6_check_ansible-lint/2_inventory.yaml @@ -0,0 +1,24 @@ +--- +gruppo_test: + hosts: + host1test.mydomain.xyz: + ansible_host: 127.0.0.2 + host2test.mydomain.xyz: + ansible_host: 127.0.0.3 + vars: + ansible_user: nobody + +gruppo_prod: + + hosts: + host1prod.mydomain.xyz: + ansible_host: 127.0.0.4 + host2prod.mydomain.xyz: + ansible_host: 127.0.0.5 + vars: + ansible_user: root + +gruppo_all: + children: + gruppo_test: + gruppo_prod: diff --git a/6_check_ansible-lint/README.md b/6_check_ansible-lint/README.md new file mode 100644 index 0000000..cbae4f8 --- /dev/null +++ b/6_check_ansible-lint/README.md @@ -0,0 +1,54 @@ +# Controllo della sintassi di un playbook con ansible lint + +Prima di procedere, verificare che il pacchetto ansible-lint sia installato → # ansible-lint --version +nel caso in cui non sia installato, installarlo con i seguenti comandi: + +- Installazione su OracleLinux8 +``` +dnf install ansible-lint -y +``` +- Installazione su OracleLinux9 +``` +dnf install ansible-lint -y +``` +- Installazione du Debian12 +``` +apt-get update +apt-get install ansible-lint -y +``` + +1) Esempio di check su un playbook che presena errori sintattici quali spazi vuoti o identazione non corretta +- per lanciare il check sul playbook: +``` +ansible-lint 1_playbook.yaml +``` + +1.1) Esempio di check su un playbook che non presena errori sintattici +- per lanciare il playbook: +``` +ansible-lint 11_playbook.yaml +``` + +1.2) Verifica delle differenze tra i due files appena testati con ansible-lint +- confronto dei files con vimdiff: +``` +vimdiff 1_playbook.yaml 11_playbook.yaml +``` + +2) Esempio di check su un inventory (in formato yaml) che presena errori sintattici quali spazi vuoti o identazione non corretta +- per lanciare il check sull'inventory: +``` +ansible-lint 2_inventory.yaml +``` + +2.1) Esempio di check su un inventory (in formato yaml) che non presena errori sintattici +- per lanciare il check sull'inventory: +``` +ansible-lint 21_inventory.yaml +``` + +2.2) Verifica delle differenze tra i due files appena testati con ansible-lint +- confronto dei files con vimdiff: +``` +vimdiff 2_inventory.yaml 21_inventory.yaml +```