Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
elearning:workbooks:centos:8:lcf900:l703 [2022/05/17 08:04] adminelearning:workbooks:centos:8:lcf900:l703 [2024/11/30 10:56] (Version actuelle) admin
Ligne 1: Ligne 1:
 ~~PDF:LANDSCAPE~~ ~~PDF:LANDSCAPE~~
  
-Version - **2022.01**+Version - **2024.01**
  
 Dernière mise-à-jour : ~~LASTMOD~~ Dernière mise-à-jour : ~~LASTMOD~~
  
-====== LCF703 - Rôles, Gabarits et Hiérarchie des Variables======+====== LDF903 - Rôles, GabaritsVariables et Facts======
  
 =====Contenu du Module===== =====Contenu du Module=====
  
-  * **LCF703 - Rôles, Gabarits et Hiérarchie des Variables**+  * **LDF903 - Rôles, GabaritsVariables et Facts**
     * Contenu du Module     * Contenu du Module
     * LAB #1 - Dépendances de Rôles     * LAB #1 - Dépendances de Rôles
Ligne 25: Ligne 25:
         * 2.6.2 - Le Gabarit Enfant         * 2.6.2 - Le Gabarit Enfant
     * LAB #3 - Gestion de la Hiérarchie des Variables     * LAB #3 - Gestion de la Hiérarchie des Variables
 +    * LAB #4 - Utilisation des Facts d'Ansible
 +    * LAB #5 - La Commande ansible-vault
 +      * 5.1 - Crypter le Fichier
 +      * 5.2 - Editer le Fichier
 +      * 5.3 - Décrypter le Fichier
 +      * 5.4 - Utilisation de Mots de Passe Aléatoires
 +    * LAB #6 - Ansible par la Pratique
 +      * 6.1 - Instructions
 +      * 6.2 - Corrigés
  
 =====LAB #1 - Dépendances de Rôles===== =====LAB #1 - Dépendances de Rôles=====
Ligne 33: Ligne 42:
  
 <code> <code>
-[trainee@centos8 ~]$ mkdir /home/trainee/.ansible/roles/exemple01.java/ +trainee@debian11:~$ mkdir /home/trainee/.ansible/roles/exemple01.java/ 
-[trainee@centos8 ~]$ cd /home/trainee/.ansible/roles/exemple01.java/ +trainee@debian11:~$ cd /home/trainee/.ansible/roles/exemple01.java/ 
-[trainee@centos8 exemple01.java]$ mkdir defaults tasks templates +trainee@debian11:~/.ansible/roles/exemple01.java$ mkdir defaults tasks templates 
-[trainee@centos8 exemple01.java]+trainee@debian11:~/.ansible/roles/exemple01.java$ 
 </code> </code>
  
Ligne 46: Ligne 55:
  
 <code> <code>
-[trainee@centos8 exemple01.java]$ vi /home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml +trainee@debian11:~/.ansible/roles/exemple01.java$ vi /home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml 
-[trainee@centos8 exemple01.java]$ cat /home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml+trainee@debian11:~/.ansible/roles/exemple01.java$ cat /home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml
 --- ---
 - name: install jre - name: install jre
Ligne 68: Ligne 77:
  
 <code> <code>
-[trainee@centos8 exemple01.java]$ vi /home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml +trainee@debian11:~/.ansible/roles/exemple01.java$ vi /home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml 
-[trainee@centos8 exemple01.java]$ cat /home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml+trainee@debian11:~/.ansible/roles/exemple01.java$ cat /home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml
 --- ---
 java_home: /usr/lib/jvm/java-8-openjdk-amd64/jre java_home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Ligne 82: Ligne 91:
  
 <code> <code>
-[trainee@centos8 exemple01.java]$ touch /home/trainee/.ansible/roles/exemple01.java/templates/java.sh+trainee@debian11:~/.ansible/roles/exemple01.java$ touch /home/trainee/.ansible/roles/exemple01.java/templates/java.sh
 </code> </code>
  
Ligne 92: Ligne 101:
  
 <code> <code>
-[trainee@centos8 exemple01.java]$ mkdir /home/trainee/.ansible/roles/tomcat/ +trainee@debian11:~/.ansible/roles/exemple01.java$ mkdir /home/trainee/.ansible/roles/tomcat/ 
-[trainee@centos8 exemple01.java]$ cd /home/trainee/.ansible/roles/tomcat/ +trainee@debian11:~/.ansible/roles/exemple01.java$ cd /home/trainee/.ansible/roles/tomcat/ 
-[trainee@centos8 tomcat]$ mkdir meta tasks+trainee@debian11:~/.ansible/roles/tomcat$ mkdir meta tasks
 </code> </code>
  
Ligne 104: Ligne 113:
  
 <code> <code>
-[trainee@centos8 tomcat]$ vi /home/trainee/.ansible/roles/tomcat/tasks/main.yaml +trainee@debian11:~/.ansible/roles/tomcat$ vi /home/trainee/.ansible/roles/tomcat/tasks/main.yaml 
-[trainee@centos8 tomcat]$ cat /home/trainee/.ansible/roles/tomcat/tasks/main.yaml+trainee@debian11:~/.ansible/roles/tomcat$ cat /home/trainee/.ansible/roles/tomcat/tasks/main.yaml
 --- ---
 - name: install tomcat - name: install tomcat
Ligne 114: Ligne 123:
  
 <code> <code>
-[trainee@centos8 tomcat]$ vi /home/trainee/.ansible/roles/tomcat/meta/main.yaml +trainee@debian11:~/.ansible/roles/tomcat$ vi /home/trainee/.ansible/roles/tomcat/meta/main.yaml 
-[trainee@centos8 tomcat]$ cat /home/trainee/.ansible/roles/tomcat/meta/main.yaml+trainee@debian11:~/.ansible/roles/tomcat$ cat /home/trainee/.ansible/roles/tomcat/meta/main.yaml
 --- ---
 dependencies: dependencies:
Ligne 128: Ligne 137:
  
 <code> <code>
-[trainee@centos8 tomcat]$ vi /home/trainee/.ansible/roles/playbook.yaml +trainee@debian11:~/.ansible/roles/tomcat$ vi /home/trainee/.ansible/roles/playbook.yaml 
-[trainee@centos8 tomcat]$ cat /home/trainee/.ansible/roles/playbook.yaml+trainee@debian11:~/.ansible/roles/tomcat$ cat /home/trainee/.ansible/roles/playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 144: Ligne 153:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/tomcat$ cd /home/trainee/.ansible/roles/ +trainee@debian11:~/.ansible/roles/tomcat$ cd /home/trainee/.ansible/roles/ 
-trainee@ansible:~/.ansible/roles$ cp ~/inventory .+trainee@debian11:~/.ansible/roles$ cp ~/inventory .
 </code> </code>
  
Ligne 151: Ligne 160:
  
 <code> <code>
-[trainee@centos8 roles]$ tree+trainee@debian11:~/.ansible/roles$ tree
 . .
 ├── exemple01.java ├── exemple01.java
Ligne 181: Ligne 190:
 │       ├── Debian-10.yml │       ├── Debian-10.yml
 │       ├── Debian-11.yml │       ├── Debian-11.yml
 +│       ├── Debian-12.yml
 │       ├── Debian-8.yml │       ├── Debian-8.yml
 │       ├── Debian-9.yml │       ├── Debian-9.yml
Ligne 187: Ligne 197:
 │       ├── RedHat-7.yml │       ├── RedHat-7.yml
 │       ├── RedHat-8.yml │       ├── RedHat-8.yml
 +│       ├── RedHat-9.yml
 │       ├── Ubuntu-12.yml │       ├── Ubuntu-12.yml
 │       ├── Ubuntu-14.yml │       ├── Ubuntu-14.yml
 │       ├── Ubuntu-16.yml │       ├── Ubuntu-16.yml
 │       ├── Ubuntu-18.yml │       ├── Ubuntu-18.yml
-│       ── Ubuntu-20.yml+│       ── Ubuntu-20.yml 
 +│       └── Ubuntu-22.yml
 ├── inventory ├── inventory
 ├── playbook.yaml ├── playbook.yaml
Ligne 200: Ligne 212:
         └── main.yaml         └── main.yaml
  
-15 directories, 31 files+15 directories, 34 files
 </code> </code>
  
Ligne 206: Ligne 218:
    
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l web01+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l web01
  
-PLAY [all] *******************************************************************************************************************************************************************************************************+PLAY [all] ***************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] *******************************************************************************************************************************************************************************************+TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
 ok: [web01] ok: [web01]
  
-TASK [exemple01.java : install jre] ******************************************************************************************************************************************************************************+TASK [exemple01.java : install jre] **************************************************************************************************************************************************************************
 ok: [web01] ok: [web01]
  
-TASK [exemple01.java : configure java home] **********************************************************************************************************************************************************************+TASK [exemple01.java : configure java home] ******************************************************************************************************************************************************************
 changed: [web01] changed: [web01]
  
-TASK [tomcat : install tomcat] ***********************************************************************************************************************************************************************************+TASK [tomcat : install tomcat] *******************************************************************************************************************************************************************************
 changed: [web01] changed: [web01]
  
-PLAY RECAP *******************************************************************************************************************************************************************************************************+PLAY RECAP ***************************************************************************************************************************************************************************************************
 web01                      : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    web01                      : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 </code> </code>
Ligne 233: Ligne 245:
  
 <code> <code>
-[trainee@centos8 roles]$ ssh web01+trainee@debian11:~/.ansible/roles$ ssh web01
 Debian GNU/Linux 9 Debian GNU/Linux 9
 Linux web01.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 Linux web01.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64
Ligne 243: Ligne 255:
 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
 permitted by applicable law. permitted by applicable law.
-Last login: Wed Mar  9 13:49:26 2022 from 10.0.2.45+Last login: Sat Sep 23 18:10:50 2023 from 10.0.2.46
 trainee@web01:~$ systemctl status tomcat8 trainee@web01:~$ systemctl status tomcat8
 ● tomcat8.service - LSB: Start Tomcat. ● tomcat8.service - LSB: Start Tomcat.
    Loaded: loaded (/etc/init.d/tomcat8; generated; vendor preset: enabled)    Loaded: loaded (/etc/init.d/tomcat8; generated; vendor preset: enabled)
-   Active: active (running) since Wed 2022-03-09 13:50:11 CET; 1min 13s ago+   Active: active (running) since Sat 2023-09-23 18:11:29 CEST; 1min 7s ago
      Docs: man:systemd-sysv-generator(8)      Docs: man:systemd-sysv-generator(8)
    CGroup: /system.slice/tomcat8.service    CGroup: /system.slice/tomcat8.service
-           └─11904 /usr/lib/jvm/default-java/bin/java -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headle+           └─25102 /usr/lib/jvm/default-java/bin/java -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.he
 trainee@web01:~$ exit trainee@web01:~$ exit
 déconnexion déconnexion
 Connection to web01 closed. Connection to web01 closed.
-[trainee@centos8 roles]+trainee@debian11:~/.ansible/roles$ 
 </code> </code>
  
Ligne 260: Ligne 272:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/tomcat/meta/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/tomcat/meta/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/tomcat/meta/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/tomcat/meta/main.yaml
 --- ---
 dependencies: dependencies:
Ligne 274: Ligne 286:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l web02+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l web02
  
-PLAY [all] *******************************************************************************************************************************************************************************************************+PLAY [all] ***************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] *******************************************************************************************************************************************************************************************+TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
 ok: [web02] ok: [web02]
  
-TASK [exemple01.java : install jre] ******************************************************************************************************************************************************************************+TASK [exemple01.java : install jre] **************************************************************************************************************************************************************************
 changed: [web02] changed: [web02]
  
-TASK [exemple01.java : configure java home] **********************************************************************************************************************************************************************+TASK [exemple01.java : configure java home] ******************************************************************************************************************************************************************
 changed: [web02] changed: [web02]
  
-TASK [tomcat : install tomcat] ***********************************************************************************************************************************************************************************+TASK [tomcat : install tomcat] *******************************************************************************************************************************************************************************
 changed: [web02] changed: [web02]
  
-PLAY RECAP ******************************************************************************************************************************************************************************************************* +PLAY RECAP *************************************************************************************************************************************************************************************************** 
-web02                      : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    +web02                      : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0     
 </code> </code>
  
Ligne 297: Ligne 309:
  
 <code> <code>
-[trainee@centos8 roles]$ ssh web02+trainee@debian11:~/.ansible/roles$ ssh web02
 Debian GNU/Linux 9 Debian GNU/Linux 9
 Linux web02.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 Linux web02.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64
Ligne 307: Ligne 319:
 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
 permitted by applicable law. permitted by applicable law.
-Last login: Wed Mar  9 13:53:57 2022 from 10.0.2.45+Last login: Sat Sep 23 18:14:46 2023 from 10.0.2.46
 trainee@web02:~$ which tree trainee@web02:~$ which tree
 /usr/bin/tree /usr/bin/tree
Ligne 313: Ligne 325:
 déconnexion déconnexion
 Connection to web02 closed. Connection to web02 closed.
-[trainee@centos8 roles]$ ssh web03 +trainee@debian11:~/.ansible/roles$
-Debian GNU/Linux 9 +
-Linux web03.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 +
- +
-The programs included with the Debian GNU/Linux system are free software; +
-the exact distribution terms for each program are described in the +
-individual files in /usr/share/doc/*/copyright. +
- +
-Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent +
-permitted by applicable law. +
-Last login: Wed Mar  9 12:12:51 2022 from 10.0.2.45 +
-trainee@web03:~$ which tree +
-trainee@web03:~$ exit +
-déconnexion +
-Connection to web03 closed. +
-[trainee@centos8 roles]+
 </code> </code>
  
Ligne 335: Ligne 332:
 ====2.1 - Variables==== ====2.1 - Variables====
  
-Les **Gabarits** ou //Templates// d'Ansible utilisent une bibliothèque Python qui s'appelle **[[http://jinja.pocoo..org/|Jinja2]]**.+Les **Gabarits** ou //Templates// d'Ansible utilisent une bibliothèque Python qui s'appelle **[[http://jinja.pocoo.org/|Jinja2]]**.
  
 <WRAP center round important 60%> <WRAP center round important 60%>
Ligne 346: Ligne 343:
  
 <code> <code>
-[trainee@centos8 roles]$ mkdir /home/trainee/.ansible/roles/haproxy/ +trainee@debian11:~/.ansible/roles$ mkdir /home/trainee/.ansible/roles/haproxy/ 
-[trainee@centos8 roles]$ cd /home/trainee/.ansible/roles/haproxy/ +trainee@debian11:~/.ansible/roles$ cd /home/trainee/.ansible/roles/haproxy/ 
-[trainee@centos8 haproxy]$ mkdir defaults handlers tasks templates +trainee@debian11:~/.ansible/roles/haproxy$ mkdir defaults handlers tasks templates 
-[trainee@centos8 haproxy]$+trainee@debian11:~/.ansible/roles/haproxy$
 </code> </code>
  
Ligne 359: Ligne 356:
  
 <code> <code>
-[trainee@centos8 haproxy]$ vi /home/trainee/.ansible/roles/haproxy/tasks/main.yaml +trainee@debian11:~/.ansible/roles/haproxy$ vi /home/trainee/.ansible/roles/haproxy/tasks/main.yaml 
-[trainee@centos8 haproxy]$ cat /home/trainee/.ansible/roles/haproxy/tasks/main.yaml+trainee@debian11:~/.ansible/roles/haproxy$ cat /home/trainee/.ansible/roles/haproxy/tasks/main.yaml
 ---  --- 
 - name: install - name: install
Ligne 385: Ligne 382:
  
 <code> <code>
-[trainee@centos8 haproxy]$ vi /home/trainee/.ansible/roles/haproxy/handlers/main.yaml +trainee@debian11:~/.ansible/roles/haproxy$ vi /home/trainee/.ansible/roles/haproxy/handlers/main.yaml 
-[trainee@centos8 haproxy]$ cat /home/trainee/.ansible/roles/haproxy/handlers/main.yaml+trainee@debian11:~/.ansible/roles/haproxy$ cat /home/trainee/.ansible/roles/haproxy/handlers/main.yaml
 --- ---
 - name: reload haproxy - name: reload haproxy
Ligne 395: Ligne 392:
  
 <code> <code>
-[trainee@centos8 haproxy]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +trainee@debian11:~/.ansible/roles/haproxy$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-[trainee@centos8 haproxy]$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+trainee@debian11:~/.ansible/roles/haproxy$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
 global global
         log /dev/log    local0         log /dev/log    local0
Ligne 459: Ligne 456:
  
 <code> <code>
-[trainee@centos8 haproxy]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +trainee@debian11:~/.ansible/roles/haproxy$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-[trainee@centos8 haproxy]$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+trainee@debian11:~/.ansible/roles/haproxy$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml
 --- ---
 haproxy_listen_address: 0.0.0.0 haproxy_listen_address: 0.0.0.0
Ligne 470: Ligne 467:
  
 <code> <code>
-[trainee@centos8 haproxy]$ cd .. +trainee@debian11:~/.ansible/roles/haproxy$ cd .. 
-[trainee@centos8 roles]$ vi playbook.yaml +trainee@debian11:~/.ansible/roles$ vi playbook.yaml 
-[trainee@centos8 roles]$ cat playbook.yaml+trainee@debian11:~/.ansible/roles$ cat playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 483: Ligne 480:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l equilibrage+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage
  
-PLAY [all] *******************************************************************************************************************************************************************************************************+PLAY [all] ***************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] *******************************************************************************************************************************************************************************************+TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-TASK [haproxy : install] *****************************************************************************************************************************************************************************************+TASK [haproxy : install] *************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-TASK [haproxy : configure] ***************************************************************************************************************************************************************************************+TASK [haproxy : configure] ***********************************************************************************************************************************************************************************
 changed: [web04] changed: [web04]
  
-TASK [haproxy : service] *****************************************************************************************************************************************************************************************+TASK [haproxy : service] *************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-RUNNING HANDLER [haproxy : reload haproxy] ***********************************************************************************************************************************************************************+RUNNING HANDLER [haproxy : reload haproxy] *******************************************************************************************************************************************************************
 changed: [web04] changed: [web04]
  
-PLAY RECAP ******************************************************************************************************************************************************************************************************* +PLAY RECAP *************************************************************************************************************************************************************************************************** 
-web04                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   +web04                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
 </code> </code>
  
Ligne 509: Ligne 506:
  
 <code> <code>
-[trainee@centos8 roles]$ ssh web04+trainee@debian11:~/.ansible/roles$ ssh web04
 Debian GNU/Linux 9 Debian GNU/Linux 9
 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64
Ligne 519: Ligne 516:
 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
 permitted by applicable law. permitted by applicable law.
-Last login: Wed Mar  9 15:23:48 2022 from 10.0.2.45+Last login: Sat Sep 23 18:24:17 2023 from 10.0.2.46
  
 trainee@web04:~$ systemctl status haproxy trainee@web04:~$ systemctl status haproxy
 ● haproxy.service - HAProxy Load Balancer ● haproxy.service - HAProxy Load Balancer
    Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled)    Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled)
-   Active: active (running) since Wed 2022-03-09 12:03:47 CET3h 20min ago+   Active: active (running) since Wed 2023-09-20 15:39:42 CEST3 days ago
      Docs: man:haproxy(1)      Docs: man:haproxy(1)
            file:/usr/share/doc/haproxy/configuration.txt.gz            file:/usr/share/doc/haproxy/configuration.txt.gz
-  Process: 9089 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS) +  Process: 16494 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS) 
-  Process: 9087 ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=0/SUCCESS) +  Process: 16492 ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=0/SUCCESS) 
- Main PID: 5394 (haproxy-systemd)+ Main PID: 2970 (haproxy-systemd)
     Tasks: 3 (limit: 4915)     Tasks: 3 (limit: 4915)
    CGroup: /system.slice/haproxy.service    CGroup: /system.slice/haproxy.service
-           ├─5394 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid +           ├─ 2970 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid 
-           ├─9091 /usr/sbin/haproxy-master +           ├─16500 /usr/sbin/haproxy-master 
-           └─9093 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds -sf 5400+           └─16501 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds -sf 2975
  
 trainee@web04:~$ cat /etc/haproxy/haproxy.cfg trainee@web04:~$ cat /etc/haproxy/haproxy.cfg
Ligne 594: Ligne 591:
 déconnexion déconnexion
 Connection to web04 closed. Connection to web04 closed.
-[trainee@centos8 roles]+trainee@debian11:~/.ansible/roles$ 
 </code> </code>
  
Ligne 608: Ligne 605:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-[trainee@centos8 roles]$ tail -n 17 /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+trainee@debian11:~/.ansible/roles$ tail -n 17 /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
 frontend haproxy frontend haproxy
     bind {{ haproxy_listen_address }}:{{haproxy_listen_port}}     bind {{ haproxy_listen_address }}:{{haproxy_listen_port}}
Ligne 636: Ligne 633:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml
 --- ---
 haproxy_listen_address: 0.0.0.0 haproxy_listen_address: 0.0.0.0
Ligne 652: Ligne 649:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l equilibrage+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage
  
-PLAY [all] *******************************************************************************************************************************************************************************************************+PLAY [all] ***************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] *******************************************************************************************************************************************************************************************+TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-TASK [haproxy : install] *****************************************************************************************************************************************************************************************+TASK [haproxy : install] *************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-TASK [haproxy : configure] ***************************************************************************************************************************************************************************************+TASK [haproxy : configure] ***********************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-TASK [haproxy : service] *****************************************************************************************************************************************************************************************+TASK [haproxy : service] *************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-PLAY RECAP ******************************************************************************************************************************************************************************************************* +PLAY RECAP *************************************************************************************************************************************************************************************************** 
-web04                      : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  +web04                      : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 </code> </code>
  
Ligne 675: Ligne 672:
  
 <code> <code>
-[trainee@centos8 roles]$ ssh web04+trainee@debian11:~/.ansible/roles$ ssh web04
 Debian GNU/Linux 9 Debian GNU/Linux 9
 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64
Ligne 686: Ligne 683:
 permitted by applicable law. permitted by applicable law.
 Last login: Wed Mar  9 15:29:27 2022 from 10.0.2.45 Last login: Wed Mar  9 15:29:27 2022 from 10.0.2.45
 +
 trainee@web04:~$ tail -n 17 /etc/haproxy/haproxy.cfg trainee@web04:~$ tail -n 17 /etc/haproxy/haproxy.cfg
         errorfile 504 /etc/haproxy/errors/504.http         errorfile 504 /etc/haproxy/errors/504.http
Ligne 704: Ligne 702:
     server web02 10.0.2.55:8080 check     server web02 10.0.2.55:8080 check
     server web03 10.0.2.56:8080 check     server web03 10.0.2.56:8080 check
 +
 trainee@web04:~$ exit trainee@web04:~$ exit
 déconnexion déconnexion
 Connection to web04 closed. Connection to web04 closed.
-[trainee@centos8 roles]+trainee@debian11:~/.ansible/roles$ 
 </code> </code>
  
Ligne 717: Ligne 716:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml
 --- ---
 haproxy_listen_address: 0.0.0.0 haproxy_listen_address: 0.0.0.0
Ligne 734: Ligne 733:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l equilibrage+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage
  
-PLAY [all] *******************************************************************************************************************************************************************************************************+PLAY [all] ***************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] *******************************************************************************************************************************************************************************************+TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-TASK [haproxy : install] *****************************************************************************************************************************************************************************************+TASK [haproxy : install] *************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-TASK [haproxy : configure] ***************************************************************************************************************************************************************************************+TASK [haproxy : configure] ***********************************************************************************************************************************************************************************
 changed: [web04] changed: [web04]
  
-TASK [haproxy : service] *****************************************************************************************************************************************************************************************+TASK [haproxy : service] *************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-RUNNING HANDLER [haproxy : reload haproxy] ***********************************************************************************************************************************************************************+RUNNING HANDLER [haproxy : reload haproxy] *******************************************************************************************************************************************************************
 changed: [web04] changed: [web04]
  
-PLAY RECAP ******************************************************************************************************************************************************************************************************* +PLAY RECAP *************************************************************************************************************************************************************************************************** 
-web04                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 +web04                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
 </code> </code>
  
Ligne 760: Ligne 759:
  
 <code> <code>
-[trainee@centos8 roles]$ ssh web04+trainee@debian11:~/.ansible/roles$ ssh web04
 Debian GNU/Linux 9 Debian GNU/Linux 9
 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64
Ligne 770: Ligne 769:
 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
 permitted by applicable law. permitted by applicable law.
-Last login: Wed Mar  9 15:32:20 2022 from 10.0.2.45+Last login: Sat Sep 23 18:31:28 2023 from 10.0.2.46 
 trainee@web04:~$ tail -n 17 /etc/haproxy/haproxy.cfg trainee@web04:~$ tail -n 17 /etc/haproxy/haproxy.cfg
         errorfile 408 /etc/haproxy/errors/408.http         errorfile 408 /etc/haproxy/errors/408.http
Ligne 789: Ligne 789:
     server web02 10.0.2.55:8080 check     server web02 10.0.2.55:8080 check
     server web03 10.0.2.56:8080 check     server web03 10.0.2.56:8080 check
 +
 trainee@web04:~$ exit trainee@web04:~$ exit
 déconnexion déconnexion
 Connection to web04 closed. Connection to web04 closed.
-[trainee@centos8 roles]+trainee@debian11:~/.ansible/roles$
 </code> </code>
  
Ligne 822: Ligne 823:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml
 --- ---
 haproxy_listen_address: 0.0.0.0 haproxy_listen_address: 0.0.0.0
Ligne 841: Ligne 842:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-[trainee@centos8 roles]$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+trainee@debian11:~/.ansible/roles$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
     stats auth admin:admin     stats auth admin:admin
 {% endif %} {% endif %}
Ligne 858: Ligne 859:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml
 --- ---
 haproxy_listen_address: 0.0.0.0 haproxy_listen_address: 0.0.0.0
Ligne 875: Ligne 876:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-[trainee@centos8 roles]$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+trainee@debian11:~/.ansible/roles$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
     stats auth admin:admin     stats auth admin:admin
 {% endif %} {% endif %}
Ligne 894: Ligne 895:
  
 <code> <code>
-[trainee@centos8 roles]$ vi backend.j2 +trainee@debian11:~/.ansible/roles$ vi backend.j2 
-[trainee@centos8 roles]$ cat backend.j2+trainee@debian11:~/.ansible/roles$ cat backend.j2
 {% macro backend(name, ip, port=8080) -%} {% macro backend(name, ip, port=8080) -%}
     server {{ name }} {{ ip }}:{{ port }} check     server {{ name }} {{ ip }}:{{ port }} check
Ligne 904: Ligne 905:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-[trainee@centos8 roles]$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+trainee@debian11:~/.ansible/roles$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
 {% endif %} {% endif %}
     balance roundrobin     balance roundrobin
Ligne 925: Ligne 926:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-[trainee@centos8 roles]$ tail -n 17 /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+trainee@debian11:~/.ansible/roles$ tail -n 17 /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
     bind {{ haproxy_listen_address }}:{{haproxy_listen_port|default('80') }}     bind {{ haproxy_listen_address }}:{{haproxy_listen_port|default('80') }}
     mode http     mode http
Ligne 949: Ligne 950:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml
 --- ---
 haproxy_listen_address: 0.0.0.0 haproxy_listen_address: 0.0.0.0
Ligne 964: Ligne 965:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l equilibrage+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 990: Ligne 991:
  
 <code> <code>
-[trainee@centos8 roles]$ ssh web04+trainee@debian11:~/.ansible/roles$ ssh web04
 Debian GNU/Linux 9 Debian GNU/Linux 9
 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64
Ligne 1022: Ligne 1023:
 déconnexion déconnexion
 Connection to web04 closed. Connection to web04 closed.
-[trainee@centos8 roles]+trainee@debian11:~/.ansible/roles$ 
 </code> </code>
  
Ligne 1080: Ligne 1081:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
 global global
         log /dev/log    local0         log /dev/log    local0
Ligne 1116: Ligne 1117:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg
 {% extends 'haproxy.cfg' %} {% extends 'haproxy.cfg' %}
 {% block globals %} {% block globals %}
Ligne 1165: Ligne 1166:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/tasks/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/tasks/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/tasks/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/tasks/main.yaml
 --- ---
 - name: install - name: install
Ligne 1187: Ligne 1188:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l equilibrage+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1213: Ligne 1214:
  
 <code> <code>
-[trainee@centos8 roles]$ ssh web04+trainee@debian11:~/.ansible/roles$ ssh web04
 Debian GNU/Linux 9 Debian GNU/Linux 9
 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 Linux web04.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64
Ligne 1273: Ligne 1274:
 déconnexion déconnexion
 Connection to web04 closed. Connection to web04 closed.
-[trainee@centos8 roles]+trainee@debian11:~/.ansible/roles$ 
 </code> </code>
  
Ligne 1304: Ligne 1305:
  
 <code> <code>
-[trainee@centos8 roles]$ cd ../../ +trainee@debian11:~/.ansible/roles$ cd ../../ 
-[trainee@centos8 ~]$ mkdir /home/trainee/.ansible/roles/debug +trainee@debian11:~$ mkdir /home/trainee/.ansible/roles/debug 
-[trainee@centos8 ~]$ mkdir /home/trainee/.ansible/roles/debug/defaults +trainee@debian11:~$ mkdir /home/trainee/.ansible/roles/debug/defaults 
-[trainee@centos8 ~]$ mkdir /home/trainee/.ansible/roles/debug/tasks +trainee@debian11:~$ mkdir /home/trainee/.ansible/roles/debug/tasks 
-[trainee@centos8 ~]+trainee@debian11:~$ 
 </code> </code>
  
Ligne 1314: Ligne 1315:
  
 <code> <code>
-[trainee@centos8 ~]$ touch /home/trainee/.ansible/roles/debug/defaults/main.yaml +trainee@debian11:~$ touch /home/trainee/.ansible/roles/debug/defaults/main.yaml 
-[trainee@centos8 ~]$ touch  /home/trainee/.ansible/roles/debug/tasks/main.yaml +trainee@debian11:~$ touch  /home/trainee/.ansible/roles/debug/tasks/main.yaml 
-[trainee@centos8 ~]+trainee@debian11:~$ 
 </code> </code>
  
Ligne 1322: Ligne 1323:
  
 <code> <code>
-[trainee@centos8 ~]$ cd .ansible/roles/ +trainee@debian11:~$ cd .ansible/roles/ 
-[trainee@centos8 roles]$ tree debug+trainee@debian11:~/.ansible/roles$ tree debug
 debug debug
 ├── defaults ├── defaults
Ligne 1336: Ligne 1337:
  
 <code> <code>
-[trainee@centos8 roles]$ mkdir /home/trainee/.ansible/roles/group_vars +trainee@debian11:~/.ansible/roles$ mkdir /home/trainee/.ansible/roles/group_vars 
-[trainee@centos8 roles]$ touch /home/trainee/.ansible/roles/group_vars/all.yaml +trainee@debian11:~/.ansible/roles$ touch /home/trainee/.ansible/roles/group_vars/all.yaml 
-[trainee@centos8 roles]+trainee@debian11:~/.ansible/roles$ 
 </code> </code>
  
Ligne 1344: Ligne 1345:
  
 <code> <code>
-[trainee@centos8 roles]$ tree group_vars/+trainee@debian11:~/.ansible/roles$ tree group_vars/
 group_vars/ group_vars/
 └── all.yaml └── all.yaml
Ligne 1354: Ligne 1355:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/debug/tasks/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/debug/tasks/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/debug/tasks/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/debug/tasks/main.yaml
 --- ---
 - debug: - debug:
Ligne 1364: Ligne 1365:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/playbook.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/playbook.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/playbook.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 1375: Ligne 1376:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1409: Ligne 1410:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/debug/defaults/main.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/debug/defaults/main.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/debug/defaults/main.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/debug/defaults/main.yaml
 --- ---
 endroit: 'roles/debug/defaults/main.yaml' endroit: 'roles/debug/defaults/main.yaml'
Ligne 1418: Ligne 1419:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1456: Ligne 1457:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/group_vars/all.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/group_vars/all.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/group_vars/all.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/group_vars/all.yaml
 --- ---
 endroit: 'roles/group_vars/all.yaml' endroit: 'roles/group_vars/all.yaml'
Ligne 1469: Ligne 1470:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1507: Ligne 1508:
  
 <code> <code>
-[trainee@centos8 roles]$ vi playbook.yaml +trainee@debian11:~/.ansible/roles$ vi playbook.yaml 
-[trainee@centos8 roles]$ cat playbook.yaml+trainee@debian11:~/.ansible/roles$ cat playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 1518: Ligne 1519:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1556: Ligne 1557:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/group_vars/group1.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/group_vars/group1.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/group_vars/group1.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/group_vars/group1.yaml
 --- ---
 endroit: 'group_vars/group1.yaml' endroit: 'group_vars/group1.yaml'
Ligne 1565: Ligne 1566:
  
 <code> <code>
-[trainee@centos8 roles]$ mkdir /home/trainee/.ansible/roles/host_vars +trainee@debian11:~/.ansible/roles$ mkdir /home/trainee/.ansible/roles/host_vars 
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/host_vars/localhost.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/host_vars/localhost.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/host_vars/localhost.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/host_vars/localhost.yaml
 --- ---
 # endroit: 'host_vars/localhost.yaml' # endroit: 'host_vars/localhost.yaml'
Ligne 1575: Ligne 1576:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/playbook.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/playbook.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/playbook.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 1586: Ligne 1587:
  
 <code> <code>
-[trainee@centos8 roles]$ vi inventory +trainee@debian11:~/.ansible/roles$ vi inventory 
-[trainee@centos8 roles]$ cat inventory+trainee@debian11:~/.ansible/roles$ cat inventory
 localhost ansible_connection=local localhost ansible_connection=local
  
Ligne 1612: Ligne 1613:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1655: Ligne 1656:
  
 <code> <code>
-[trainee@centos8 roles]$ vi inventory +trainee@debian11:~/.ansible/roles$ vi inventory 
-[trainee@centos8 roles]$ cat inventory+trainee@debian11:~/.ansible/roles$ cat inventory
 [group1] [group1]
 localhost ansible_connection=local localhost ansible_connection=local
Ligne 1682: Ligne 1683:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1725: Ligne 1726:
  
 <code> <code>
-[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/host_vars/localhost.yaml +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/host_vars/localhost.yaml 
-[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/host_vars/localhost.yaml+trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/host_vars/localhost.yaml
 --- ---
 endroit: 'host_vars/localhost.yaml' endroit: 'host_vars/localhost.yaml'
Ligne 1734: Ligne 1735:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1777: Ligne 1778:
  
 <code> <code>
-[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -e 'endroit="la ligne de commande"'+trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -e 'endroit="la ligne de commande"'
  
 PLAY [all] ******************************************************************************************************************************************************************************************************* PLAY [all] *******************************************************************************************************************************************************************************************************
Ligne 1816: Ligne 1817:
 **Important** : La variable fixée dans sur la **ligne de commande** surcharge toutes les autres variables. **Important** : La variable fixée dans sur la **ligne de commande** surcharge toutes les autres variables.
 </WRAP> </WRAP>
 +
 +=====LAB #4 - Utilisation des Facts d'Ansible=====
 +
 +Ansible Facts sont :
 +
 +  * des variables collectées automatiquement par le module **setup** d'Ansible lors du contrôle à distance d'un hôte,
 +  * spécifiques à l'hôte concerné. 
 +
 +Il est cependant possible d'exécuter ce module manuellement afin de voir les Facts collectées :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible all -i web01, -m setup | more
 +web01 | SUCCESS => {
 +    "ansible_facts": {
 +        "ansible_all_ipv4_addresses": [
 +            "10.0.2.54"
 +        ],
 +        "ansible_all_ipv6_addresses": [
 +            "fe80::d255:17e1:74c1:306e"
 +        ],
 +        "ansible_apparmor": {
 +            "status": "disabled"
 +        },
 +        "ansible_architecture": "x86_64",
 +        "ansible_bios_date": "04/01/2014",
 +        "ansible_bios_vendor": "SeaBIOS",
 +        "ansible_bios_version": "rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org",
 +        "ansible_board_asset_tag": "NA",
 +        "ansible_board_name": "NA",
 +        "ansible_board_serial": "NA",
 +        "ansible_board_vendor": "NA",
 +        "ansible_board_version": "NA",
 +        "ansible_chassis_asset_tag": "NA",
 +        "ansible_chassis_serial": "NA",
 +        "ansible_chassis_vendor": "QEMU",
 +        "ansible_chassis_version": "pc-i440fx-5.2",
 +        "ansible_cmdline": {
 +            "BOOT_IMAGE": "/boot/vmlinuz-4.9.0-8-amd64",
 +            "quiet": true,
 +            "ro": true,
 +            "root": "UUID=b29b93ed-8de4-4980-a407-15bba3ad09ba"
 +        },
 +        "ansible_date_time": {
 +            "date": "2022-03-09",
 +            "day": "09",
 +            "epoch": "1646840799",
 +            "hour": "16",
 +            "iso8601": "2022-03-09T15:46:39Z",
 +            "iso8601_basic": "20220309T164639891872",
 +            "iso8601_basic_short": "20220309T164639",
 +            "iso8601_micro": "2022-03-09T15:46:39.891872Z",
 +            "minute": "46",
 +            "month": "03",
 +            "second": "39",
 +            "time": "16:46:39",
 +            "tz": "CET",
 +            "tz_dst": "CEST",
 +            "tz_offset": "+0100",
 +            "weekday": "mercredi",
 +            "weekday_number": "3",
 +            "weeknumber": "10",
 +            "year": "2022"
 +        },
 +        "ansible_default_ipv4": {
 +            "address": "10.0.2.54",
 +            "alias": "ens18",
 +            "broadcast": "10.0.2.255",
 +            "gateway": "10.0.2.1",
 +--More--
 +</code>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez que le nom de chaque **Fact** commence par **ansible_**. Évitez donc de créer des variables commençant var cette valeur !
 +</WRAP>
 +
 +Parmi les Facts, les plus utiles sont :
 +
 +  * "ansible_hostname": "web01",
 +  * "ansible_fqdn": "web01.i2tch.loc",
 +  * "ansible_architecture": "x86_64",
 +  * "ansible_distribution": "Debian",
 +  * "ansible_distribution_major_version": "9",
 +  * "ansible_distribution_version": "9.7",
 +  * "ansible_os_family": "Debian",
 +  * "ansible_memtotal_mb": 240,
 +  * "ansible_processor_cores": 1,
 +  * "ansible_virtualization_role": "guest".
 +
 +Ainsi que dictionnaire **ansible_default_ipv4** :
 +
 +<file>
 +        "ansible_default_ipv4": {
 +            "address": "10.0.2.54",
 +            "alias": "ens18",
 +            "broadcast": "10.0.2.255",
 +            "gateway": "10.0.2.1",
 +            "interface": "ens18",
 +            "macaddress": "de:b9:d4:17:cd:da",
 +            "mtu": 1500,
 +            "netmask": "255.255.255.0",
 +            "network": "10.0.2.0",
 +            "type": "ether"
 +        },
 +</file>
 +
 +Modifiez le fichier **inventory** en mettant les deux machines TargetA et TargetB dans le groupe **linux** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ vi inventory
 +trainee@debian11:~/.ansible/roles$ cat inventory
 +[linux]
 +targeta
 +targetb
 +
 +[group1]
 +localhost ansible_connection=local
 +
 +[basededonnees]
 +web01
 +
 +[dotcms]
 +web02
 +web03
 +
 +[equilibrage]
 +web04
 +
 +[debian:children]
 +basededonnees
 +dotcms
 +equilibrage
 +
 +[debian:vars]
 +ansible_user=trainee
 +</code>
 +
 +Modifiez le fichier **playbook.yaml** afin d'utiliser le Rôle **exemple01.java** en tant qu'utilisateur privilégié :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ vi playbook.yaml
 +trainee@debian11:~/.ansible/roles$ cat playbook.yaml
 +---
 +- hosts: all
 +  become: true
 +  roles: 
 +    - exemple01.java 
 +</code>
 +
 +Utilisez la commande scp pour copier le fichier authorized_keys de la machine virtuelle debian11 vers la machine virtuelle targetb :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ cd ~
 +trainee@debian11:~$ scp .ssh/authorized_keys trainee@10.0.2.53:/home/trainee/.ssh/authorized_keys
 +trainee@10.0.2.53's password: trainee
 +authorized_keys                                                                                                                                                                 100%  888     8.9KB/  00:00    
 +trainee@debian11:~$ cd -
 +/home/trainee/.ansible/roles
 +trainee@debian11:~/.ansible/roles$ 
 +</code>
 +
 +Grâce au Fact **ansible_os_family** il est possible d'appliquer le fichier **/home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml** aux deux distributions. Notez l'utilisation de la clause **when** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ vi exemple01.java/tasks/main.yaml
 +trainee@debian11:~/.ansible/roles$ cat exemple01.java/tasks/main.yaml
 +---
 +- name: install jre (Debian)
 +  package: name=openjdk-8-jre state=present
 +  when: ansible_os_family == 'Debian'
 +
 +- name: install jre (CentOS)
 +  package: name=java-1.8.0-openjdk state=present
 +  when: ansible_os_family == 'RedHat'
 +</code>
 +
 +Modifiez le fichier **/etc/hosts** de la machine **debian11** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ su -
 +Password: fenestros
 +
 +root@debian11:~# vi /etc/hosts
 +
 +root@debian11:~# cat /etc/hosts
 +127.0.0.1       localhost
 +10.0.2.46       debian11.ittraining.loc debian11
 +10.0.2.54 web01.i2tch.loc web01
 +10.0.2.55 web02.i2tch.loc web02
 +10.0.2.56 web03.i2tch.loc web03
 +10.0.2.57 web04.i2tch.loc web04
 +10.0.2.52 targeta.i2tch.loc targeta 
 +10.0.2.53 targetb.i2tch.loc targetb
 +
 +# The following lines are desirable for IPv6 capable hosts
 +::1     localhost ip6-localhost ip6-loopback
 +ff02::1 ip6-allnodes
 +ff02::2 ip6-allrouters
 +
 +root@debian11:~# exit
 +logout
 +
 +trainee@debian11:~/.ansible/roles$
 +</code>
 +
 +Connectez-vous en ssh à targeta et testez la configuration de sudo :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ssh targeta
 +Debian GNU/Linux 9
 +Linux targeta.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64
 +
 +The programs included with the Debian GNU/Linux system are free software;
 +the exact distribution terms for each program are described in the
 +individual files in /usr/share/doc/*/copyright.
 +
 +Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
 +permitted by applicable law.
 +Last login: Wed Sep 20 16:16:07 2023 from 10.0.2.46
 +trainee@targeta:~$
 +</code>
 +
 +Modifiez le contenu du fichier **/etc/apt/sources.list** :
 +
 +<code>
 +trainee@targeta:~$ sudo vi /etc/apt/sources.list
 +
 +trainee@targeta:~$ cat /etc/apt/sources.list
 +
 +
 +# deb cdrom:[Debian GNU/Linux 9.6.0 _Stretch_ - Official amd64 NETINST 20181110-11:34]/ stretch main
 +
 +#deb cdrom:[Debian GNU/Linux 9.6.0 _Stretch_ - Official amd64 NETINST 20181110-11:34]/ stretch main
 +
 +deb http://archive.debian.org/debian/ stretch main
 +deb-src http://archive.debian.org/debian/ stretch main
 +
 +deb http://archive.debian.org/debian-security stretch/updates main
 +deb-src http://archive.debian.org/debian-security stretch/updates main
 +
 +trainee@targeta:~$ sudo apt update
 +Ign:1 http://archive.debian.org/debian stretch InRelease
 +Réception de:2 http://archive.debian.org/debian-security stretch/updates InRelease [59,1 kB]
 +Réception de:3 http://archive.debian.org/debian stretch Release [118 kB]
 +Réception de:4 http://archive.debian.org/debian stretch Release.gpg [3 177 B]
 +Réception de:5 http://archive.debian.org/debian-security stretch/updates/main Sources [413 kB]
 +Réception de:6 http://archive.debian.org/debian-security stretch/updates/main amd64 Packages [782 kB]
 +Réception de:7 http://archive.debian.org/debian-security stretch/updates/main Translation-en [368 kB]
 +Réception de:8 http://archive.debian.org/debian stretch/main Sources [6 736 kB]
 +Réception de:9 http://archive.debian.org/debian stretch/main amd64 Packages [7 080 kB]
 +Réception de:10 http://archive.debian.org/debian stretch/main Translation-fr [1 894 kB]
 +Réception de:11 http://archive.debian.org/debian stretch/main Translation-en [5 377 kB]
 +22,8 Mo réceptionnés en 27s (843 ko/s)                                                                                                                                                                       
 +Lecture des listes de paquets... Fait
 +Construction de l'arbre des dépendances       
 +Lecture des informations d'état... Fait
 +353 packages can be upgraded. Run 'apt list --upgradable' to see them.
 +</code>
 +
 +Supprimez le paquet **openjdk-8-jre** :
 +
 +<code>
 +trainee@targeta:~$ sudo apt-get -y remove openjdk-8-jre
 +...
 +trainee@targeta:~$ exit
 +déconnexion
 +Connection to targeta closed.
 +</code>
 +
 +Connectez-vous en ssh à targetb et testez la configuration de sudo :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ssh targetb
 +The authenticity of host 'targetb (10.0.2.53)' can't be established.
 +ECDSA key fingerprint is SHA256:RgOsp/XI7JHNq+oIfHKw+jkHdtTnBIh+Dd7kVmHRxtU.
 +Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
 +Warning: Permanently added 'targetb,10.0.2.53' (ECDSA) to the list of known hosts.
 +trainee@targetb's password: 
 +Last login: Sun Mar 21 08:53:18 2021 from 10.0.2.10
 +
 +[trainee@targetb ~]$ yum clean all
 +Loaded plugins: fastestmirror, langpacks
 +Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
 +Cleaning repos: base extras updates
 +Other repos take up 119 M of disk space (use --verbose for details)
 +
 +[trainee@targetb ~]$ sudo yum -y makecache
 +Loaded plugins: fastestmirror, langpacks
 +Loading mirror speeds from cached hostfile
 + * base: centos.mirror.ate.info
 + * extras: mirror.plusserver.com
 + * updates: mirror.plusserver.com
 +base                                                                                                                                                                                       | 3.6 kB  00:00:00     
 +extras                                                                                                                                                                                     | 2.9 kB  00:00:00     
 +updates                                                                                                                                                                                    | 2.9 kB  00:00:00     
 +(1/6): extras/7/x86_64/other_db                                                                                                                                                            | 147 kB  00:00:00     
 +(2/6): base/7/x86_64/filelists_db                                                                                                                                                          | 7.2 MB  00:00:00     
 +(3/6): base/7/x86_64/other_db                                                                                                                                                              | 2.6 MB  00:00:00     
 +(4/6): extras/7/x86_64/filelists_db                                                                                                                                                        | 277 kB  00:00:00     
 +(5/6): updates/7/x86_64/other_db                                                                                                                                                           | 1.0 MB  00:00:00     
 +(6/6): updates/7/x86_64/filelists_db                                                                                                                                                       | 7.8 MB  00:00:00     
 +Metadata Cache Created
 +</code>
 +
 +Supprimez le paquet **java-1.8.0-openjdk** :
 +
 +<code>
 +[trainee@targetb ~]$ sudo yum -y remove java-1.8.0-openjdk
 +...
 +[trainee@targetb ~]$ exit
 +logout
 +Connection to targetb closed.
 +trainee@debian11:~/.ansible/roles$
 +</code>
 +
 +Exécutez **ansible-playbook** et constatez le résultat :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l linux
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +
 +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
 +ok: [targeta]
 +ok: [targetb]
 +
 +TASK [exemple01.java : install jre (Debian)] *********************************************************************************************************************************************************************
 +skipping: [targetb]
 +changed: [targeta]
 +
 +TASK [exemple01.java : install jre (CentOS)] *********************************************************************************************************************************************************************
 +skipping: [targeta]
 +changed: [targetb]
 +
 +PLAY RECAP *******************************************************************************************************************************************************************************************************
 +targeta                    : ok=2    changed=1    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   
 +targetb                    : ok=2    changed=1    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0  
 +</code>
 +
 +Les conditions peuvent être combinées grâce à **and** et **or**. En voici un exemple :
 +
 +<file>
 +tasks:
 +  - name: "Extinction des systèmes CentOS 6 et Debian 7"
 +    command: /sbin/shutdown -t now
 +    when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") or
 +          (ansible_distribution == "Debian" and ansible_distribution_major_version == "7")
 +</file>
 +
 +=====LAB #5 - La Commande ansible-vault=====
 +
 +La commande **ansible-vault** permet de créer et d'utiliser des fichiers cryptés, par exemple, ceux qui contiennent des mots de passe.
 +
 +Pour illustrer son utilisation, créez le Rôle **vault** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ mkdir vault
 +</code>
 +
 +Éditez le fichier **/home/trainee/.ansible/roles/group_vars/all.yaml** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ vi /home/trainee/.ansible/roles/group_vars/all.yaml
 +trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/group_vars/all.yaml
 +---
 +secret: gardezmoisecret
 +</code>
 +
 +Modifiez le fichier **/home/trainee/.ansible/roles/playbook.yaml** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ vi playbook.yaml
 +trainee@debian11:~/.ansible/roles$ cat playbook.yaml
 +---
 +- hosts: all
 +  tasks:
 +  - debug:
 +      msg: "Le secret est {{ secret }}"
 +</code>
 +
 +Exécutez la commande **ansible-playbook** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l localhost
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +
 +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [debug] *****************************************************************************************************************************************************************************************************
 +ok: [localhost] => {
 +    "msg": "Le secret est gardezmoisecret"
 +}
 +
 +PLAY RECAP *******************************************************************************************************************************************************************************************************
 +localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
 +</code>
 +
 +<WRAP center round important 60%>
 +**Important** : L'exécution démontre que la variable **secret** est bien lue.
 +</WRAP>
 +
 +====5.1 - Crypter le Fichier====
 +
 +Cryptez maintenant le fichier **/home/trainee/.ansible/roles/group_vars/all.yaml** en utilisant la commande **ansible-vault** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-vault encrypt group_vars/all.yaml
 +New Vault password: fenestros
 +Confirm New Vault password: fenestros
 +Encryption successful
 +trainee@debian11:~/.ansible/roles$ 
 +</code>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez que le mot de passe **fenestros** ne sera pas en clair.
 +</WRAP>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez que le mot de passe est pour la commande **ansible-vault** et non pas uniquement pour l'action de cryptage en cours.
 +</WRAP>
 +
 +Constatez maintenant le contenu du fichier **/home/trainee/.ansible/roles/group_vars/all.yaml** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/group_vars/all.yaml
 +$ANSIBLE_VAULT;1.1;AES256
 +33343664333931323331346338346439613439633633396262393733663463363438663163383761
 +6566653230323032396434356132653262313962633265630a366436666261363933343663623131
 +63373230663530313864373236316465333464323131643933363664303332336261353732623064
 +3538303864633035320a376235333637656534376638613661303765373165383936653336646562
 +31376535333861616165346433306230366231333139323062366432333033386366
 +</code>
 +
 +Exécutez de nouveau la commande **ansible-playbook** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l localhost
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +ERROR! Attempting to decrypt but no vault secrets found
 +</code>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez l'erreur due au fait que le fichier a été crypté.
 +</WRAP>
 +
 +Pour indiquer à la commande **ansible-playbook** que le fichier qui doit être lu soit crypté, utilisez l'option **--ask-vault-pass** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l localhost
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +ERROR! Attempting to decrypt but no vault secrets found
 +trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l localhost --ask-vault-pass
 +Vault password: fenestros
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +
 +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [debug] *****************************************************************************************************************************************************************************************************
 +ok: [localhost] => {
 +    "msg": "Le secret est gardezmoisecret"
 +}
 +
 +PLAY RECAP *******************************************************************************************************************************************************************************************************
 +localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
 +</code>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez que le mot de passe **fenestros** ne sera pas en clair.
 +</WRAP>
 +
 +====5.2 - Editer le Fichier====
 +
 +Pour éditer le fichier, utilisez la sous-commande **edit** de la commande **ansible-vault** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-vault edit group_vars/all.yaml
 +Vault password: fenestros
 +</code>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez que le mot de passe **fenestros** ne sera pas en clair.
 +</WRAP>
 +
 +Le fichier est chargé en mémoire pour édition :
 +
 +<code>
 +---
 +secret: gardezlesecret
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                                                                                                             
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +-- INSERT --
 +</code>
 +
 +Modifiez le secret et sauvegardez le fichier :
 +
 +<code>
 +---
 +secret: gardezlesecret
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                                                                                                             
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +~                                                                                                                                                                                                                 
 +:x
 +</code>
 +
 +Constatez que le contenu du fichier **/home/trainee/.ansible/roles/group_vars/all.yaml** est toujours crypté :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/group_vars/all.yaml
 +$ANSIBLE_VAULT;1.1;AES256
 +36633861376466313363373336643832646663666334633931663262666361306236386232316461
 +3331633863386666626230663038653136653830303465660a353337316634363465663962336365
 +61396430313965653666333738376663336139613566636437353935653232306264336235333538
 +6439366539653436310a666361313237623137666634663439343132393532623962353163303364
 +37626635363832333934363930383265313932663230356234343235643935353535
 +</code>
 +
 +Exécutez de nouveau la commande **ansible-playbook** avec l'option **--ask-vault-pass** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l localhost --ask-vault-pass
 +Vault password: fenestros
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +
 +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [debug] *****************************************************************************************************************************************************************************************************
 +ok: [localhost] => {
 +    "msg": "Le secret est gardezlesecret"
 +}
 +
 +PLAY RECAP *******************************************************************************************************************************************************************************************************
 +localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
 +</code>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez que le mot de passe **fenestros** ne sera pas en clair.
 +</WRAP>
 +
 +====5.3 - Décrypter le Fichier====
 +
 +Il est possible de décrypter le fichier en utilisant la sous-commande **decrypt** de la commande **ansible-vault** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-vault decrypt group_vars/all.yaml
 +Vault password: fenestros
 +Decryption successful
 +</code>
 +
 +<WRAP center round important 60%>
 +**Important** : Notez que le mot de passe **fenestros** ne sera pas en clair.
 +</WRAP>
 +
 +Constatez que le contenu du fichier **/home/trainee/.ansible/roles/group_vars/all.yaml** n'est plus crypté :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ cat /home/trainee/.ansible/roles/group_vars/all.yaml
 +---
 +secret: gardezlesecret
 +</code>
 +
 +====5.4 - Utilisation de Mots de Passe Aléatoires====
 +
 +Installez le paquet **pwgen** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ which pwgen
 +trainee@debian11:~/.ansible/roles$ su -
 +Password: fenestros
 +root@debian11:~# apt install pwgen
 +Reading package lists... Done
 +Building dependency tree... Done
 +Reading state information... Done
 +The following packages were automatically installed and are no longer required:
 +  libopengl0 linux-headers-5.10.0-15-amd64 linux-headers-5.10.0-15-common
 +Use 'apt autoremove' to remove them.
 +The following NEW packages will be installed:
 +  pwgen
 +0 upgraded, 1 newly installed, 0 to remove and 22 not upgraded.
 +Need to get 19.6 kB of archives.
 +After this operation, 52.2 kB of additional disk space will be used.
 +Get:1 http://deb.debian.org/debian bullseye/main amd64 pwgen amd64 2.08-2 [19.6 kB]
 +Fetched 19.6 kB in 0s (749 kB/s) 
 +Selecting previously unselected package pwgen.
 +(Reading database ... 206562 files and directories currently installed.)
 +Preparing to unpack .../pwgen_2.08-2_amd64.deb ...
 +Unpacking pwgen (2.08-2) ...
 +Setting up pwgen (2.08-2) ...
 +Processing triggers for man-db (2.9.4-2) ...
 +root@debian11:~# exit
 +logout
 +
 +trainee@debian11:~/.ansible/roles$ 
 +</code>
 +
 +Utilisez maintenant la commande **pwgen** pour générer un mot de passe aléatoire :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ pwgen 16 1
 +di3Be1AiPayeehai
 +</code>
 +
 +Utilisez pwgen pour créer un mot de passe aléatoire contenu dans un fichier :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ pwgen 16 1 > vault-password
 +
 +trainee@debian11:~/.ansible/roles$ ls
 +backend.j2  debug  exemple01.java  geerlingguy.java  group_vars  haproxy  host_vars  inventory  playbook.yaml  tomcat  vault  vault-password
 +
 +trainee@debian11:~/.ansible/roles$ cat vault-password
 +oo3aeph5PaiVeiBu
 +</code>
 +
 +Utilisez maintenant le mot de passe aléatoire contenu dans le fichier **vault-password** pour crypter le fichier **/home/trainee/.ansible/roles/group_vars/all.yaml** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-vault encrypt group_vars/all.yaml --vault-password-file vault-password
 +Encryption successful
 +</code>
 +
 +Constatez le contenu du fichier **/home/trainee/.ansible/roles/group_vars/all.yaml** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ cat group_vars/all.yaml
 +$ANSIBLE_VAULT;1.1;AES256
 +61326364653334653935643735623863353362333536396638356362376631633732306332316661
 +6662333436336237346433363637393666623165643438620a343436366136386637343238303063
 +38383866386631363834623461323334313030623136333334646335626165363263373966373663
 +3137333330653635620a396133346264656335633530353966383930613731626639393631623066
 +31323331383563373830306331653166326563333135326631363461313666313864
 +</code>
 +
 +Exécutez de nouveau la commande **ansible-playbook** avec l'option **--vault-password-file** :
 +
 +<code>
 +trainee@debian11:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l localhost --vault-password-file vault-password
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +
 +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [debug] *****************************************************************************************************************************************************************************************************
 +ok: [localhost] => {
 +    "msg": "Le secret est gardezlesecret"
 +}
 +
 +PLAY RECAP *******************************************************************************************************************************************************************************************************
 +localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  
 +</code>
 +
 +=====LAB #6 - Ansible par la Pratique=====
 +
 +Connectez-vous à la machine virtuelle **CentOS7_10.0.2.51_SSH**.
 +
 +====6.1 - Instructions ====
 +
 +Il vous est demandé d'automatiser avec Ansible :
 +
 +  * l'installation du serveur vsftpd,
 +  * la mise à jour éventuelle de firewalld,
 +  * la création d'une règle dans firewalld pour le trafic vers le serveur vsfptd,
 +  * la création sécurisée de deux comptes ftp :
 +    * user : mike
 +      * mot de passe : toto
 +    * user : bob
 +      * mot de passe : tata
 +
 +Installez donc Ansible à partir des dépôts :
 +
 +<code>
 +[trainee@centos7 ~]$ su -
 +Mot de passe : fenestros
 +Dernière connexion : jeudi 5 septembre 2019 à 18:28:51 CEST sur pts/0
 +[root@centos7 ~]# yum install epel-release
 +[root@centos7 ~]# yum install ansible
 +</code>
 +
 +Vérifiez ensuite la présence des exécutables :
 +
 +<code>
 +[root@centos7 ~]# which ansible
 +/bin/ansible
 +[root@centos7 ~]# which ansible-playbook
 +/bin/ansible-playbook
 +</code>
 +
 +Afin de vous aider, on vous fournit deux fichiers :
 +
 +<code>
 +[root@centos7 ~]# cat vsftpd.yml
 +---
 +- name: ftp server install
 +  hosts: localhost
 +  gather_facts: no
 +  become: yes
 +  vars_files:
 +    - users.yml
 +  tasks:
 +    - name: latest vsftpd version
 +      yum:
 +        name: vsftpd
 +        state: latest
 +    - name: latest firewalld version
 +        name: firewalld
 +        state: latest
 +    - name: vsftpd
 +      service:
 +        name vsftpd
 +        enabled: true
 +        state: started
 +    - name: firewalld
 +      service:
 +        name: firewalld
 +        enabled: true
 +        state: started
 +    - name: firewalld allows ftp
 +      firewalld:
 +        permanent: yes
 +        immediate: yes
 +        state: enabled
 +    - name: Create_FTP_users
 +      user:
 +        password: "{{ item.password | password_hash(sha512) }}"
 +        with_items: "{{ ftp_users }}"
 +</code>
 +
 +<code>
 +[root@centos7 ~]# ansible-vault view secrets.yml
 +Vault password: fenestros
 +ftp_users:
 + - { username: mike, password: toto }
 + - { username: bob, password: tata }
 +</code>
 +
 +Lors de l'exécution de la commande ansible-playback, vous obtenez le résultat suivant :
 +
 +<code>
 +[root@centos7 ~]# ansible-playbook vsftpd.yml
 + [WARNING]: Could not match supplied host pattern, ignoring: all
 +
 + [WARNING]: provided hosts list is empty, only localhost is available
 +
 +ERROR! Syntax Error while loading YAML.
 +
 +
 +The error appears to have been in '/root/vsftpd.yml': line 14, column 13, but may
 +be elsewhere in the file depending on the exact syntax problem.
 +
 +The offending line appears to be:
 +
 +    - name: latest firewalld version
 +        name: firewalld
 +        ^ here
 +
 +exception type: <class 'yaml.scanner.ScannerError'>
 +exception: mapping values are not allowed in this context
 + in "<unicode string>", line 14, column 13
 +</code>
 +
 +A vous de jouer !
 +
 +[isauth account,@admin]
 +
 +====6.2 - Corrigés====
 +
 +===Erreur #1===
 +
 +Éditez le fichier **vsftpd.yml** :
 +
 +<code>
 +[root@centos7 ~]# vi vsftpd.yml
 +[root@centos7 ~]# cat vsftpd.yml
 +---
 +- name: ftp server install
 +  hosts: localhost
 +  gather_facts: no
 +  become: yes
 +  vars_files:
 +    - users.yml
 +  tasks:
 +    - name: latest vsftpd version
 +      yum:
 +        name: vsftpd
 +        state: latest
 +    - name: latest firewalld version
 +      yum:   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Ajouter yum:
 +        name: firewalld
 +        state: latest
 +    - name: vsftpd
 +      service:
 +        name vsftpd
 +        enabled: true
 +        state: started
 +    - name: firewalld
 +      service:
 +        name: firewalld
 +        enabled: true
 +        state: started
 +    - name: firewalld allows ftp
 +      firewalld:
 +        permanent: yes
 +        immediate: yes
 +        state: enabled
 +    - name: Create_FTP_users
 +      user:
 +        password: "{{ item.password | password_hash(sha512) }}"
 +        with_items: "{{ ftp_users }}"
 +</code>
 +
 +Relancez la commande **ansible-playbook** :
 +
 +<code>
 +[root@centos7 ~]# ansible-playbook vsftpd.yml
 +[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 +ERROR! Syntax Error while loading YAML.
 +  mapping values are not allowed in this context
 +
 +The error appears to be in '/root/vsftpd.yml': line 20, column 16, but may
 +be elsewhere in the file depending on the exact syntax problem.
 +
 +The offending line appears to be:
 +
 +        name vsftpd
 +        enabled: true
 +               ^ here
 +</code>
 +
 +===Erreur #2===
 +
 +Editez le fichier **vsftpd.yml** :
 +
 +<code>
 +[root@centos7 ~]# vi vsftpd.yml
 +[root@centos7 ~]# cat vsftpd.yml
 +---
 +- name: ftp server install
 +  hosts: localhost
 +  gather_facts: no
 +  become: yes
 +  vars_files:
 +    - users.yml
 +  tasks:
 +    - name: latest vsftpd version
 +      yum:
 +        name: vsftpd
 +        state: latest
 +    - name: latest firewalld version
 +      yum:   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Ajouter yum:
 +        name: firewalld
 +        state: latest
 +    - name: vsftpd
 +      service:
 +        name: vsftpd <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Ajouter le caractère : après name
 +        enabled: true
 +        state: started
 +    - name: firewalld
 +      service:
 +        name: firewalld
 +        enabled: true
 +        state: started
 +    - name: firewalld allows ftp
 +      firewalld:
 +        permanent: yes
 +        immediate: yes
 +        state: enabled
 +    - name: Create_FTP_users
 +      user:
 +        password: "{{ item.password | password_hash(sha512) }}"
 +        with_items: "{{ ftp_users }}"
 +</code>
 +
 +Relancez la commande **ansible-playbook** :
 +
 +<code>
 +[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 +ERROR! vars file users.yml was not found
 +Could not find file on the Ansible Controller.
 +If you are using a module and expect the file to exist on the remote, see the remote_src option
 +</code>
 +
 +===Erreur #3===
 +
 +Créez le fichier **users.yml** :
 +
 +<code>
 +[root@centos7 ~]# vi users.yml
 +[root@centos7 ~]# cat users.yml 
 +ftp_users:
 + - { username: mike, password: toto }
 + - { username: bob, password: tata }
 +</code>
 +
 +Relancez la commande **ansible-playbook** :
 +
 +<code>
 +[root@centos7 ~]# ansible-playbook vsftpd.yml
 +[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 +
 +PLAY [ftp server install] ***********************************************************************************************************************************************
 +
 +TASK [latest vsftpd version] ********************************************************************************************************************************************
 +changed: [localhost]
 +
 +TASK [latest firewalld version] *****************************************************************************************************************************************
 +changed: [localhost]
 +
 +TASK [vsftpd] ***********************************************************************************************************************************************************
 +changed: [localhost]
 +
 +TASK [firewalld] ********************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [firewalld allows ftp] *********************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [Create_FTP_users] *************************************************************************************************************************************************
 +fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'sha512' is undefined\n\nThe error appears to be in '/root/vsftpd.yml': line 32, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        state: enabled\n    - name: Create_FTP_users\n      ^ here\n"}
 +
 +PLAY RECAP **************************************************************************************************************************************************************
 +localhost                  : ok=5    changed=3    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0  
 +</code>
 +
 +===Erreurs 4, 5 et 6===
 +
 +<code>
 +[root@centos7 ~]# vi vsftpd.yml
 +[root@centos7 ~]# cat vsftpd.yml
 +---
 +- name: ftp server install
 +  hosts: localhost
 +  gather_facts: no
 +  become: yes
 +  vars_files:
 +    - users.yml
 +  tasks:
 +    - name: latest vsftpd version
 +      yum:
 +        name: vsftpd
 +        state: latest
 +    - name: latest firewalld version
 +      yum:   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Ajouter yum:
 +        name: firewalld
 +        state: latest
 +    - name: vsftpd
 +      service:
 +        name: vsftpd <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Ajouter le caractère : après name
 +        enabled: true
 +        state: started
 +    - name: firewalld
 +      service:
 +        name: firewalld
 +        enabled: true
 +        state: started
 +    - name: firewalld allows ftp
 +      firewalld:
 +        permanent: yes
 +        immediate: yes
 +        state: enabled
 +    - name: Create_FTP_users
 +      user:
 +        name: "{{ item.username }}"  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Ajouter la ligne name:
 +        password: "{{ item.password | password_hash('sha512') }}" <<<<<<<<<<<<Entourer sha512 avec des caractères '
 +      with_items: "{{ ftp_users }}" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Aligner with_items: avec user:
 +</code>
 +
 +Relancez la commande **ansible-playbook** :
 +
 +<code>
 +[root@centos7 ~]# ansible-playbook vsftpd.yml
 +[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 +
 +PLAY [ftp server install] ***********************************************************************************************************************************************
 +
 +TASK [latest vsftpd version] ********************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [latest firewalld version] *****************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [vsftpd] ***********************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [firewalld] ********************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [firewalld allows ftp] *********************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [Create_FTP_users] *************************************************************************************************************************************************
 +changed: [localhost] => (item={u'username': u'mike', u'password': u'toto'})
 +changed: [localhost] => (item={u'username': u'bob', u'password': u'tata'})
 +
 +PLAY RECAP **************************************************************************************************************************************************************
 +localhost                  : ok=6    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  
 +</code>
 +
 +Crypter le fichier users.yml :
 +
 +<code>
 +[root@centos7 ~]# ansible-vault encrypt users.yml
 +New Vault password: fenestros
 +Confirm New Vault password: fenestros
 +Encryption successful
 +</code>
 +
 +Consultez le fichier users.yml :
 +
 +<code>
 +[root@centos7 ~]# ansible-vault view users.yml
 +Vault password: 
 +ftp_users:
 + - { username: mike, password: toto }
 + - { username: bob, password: tata }
 +
 +[root@centos7 ~]# cat users.yml 
 +$ANSIBLE_VAULT;1.1;AES256
 +30323061313265353234666230373765333865663061626362646332376639356463623238343166
 +3635356261383732373633626230353837393735393933390a323561663963666262343835363166
 +61306137383463303138656131626236633935383031323864396164366139323265653732663834
 +6130656163356661360a663635333537373961616230353766666130633537323065663161393939
 +65353936613539303631373530643536616335356461323735646165616136303839636166663232
 +38616133393235636632646461346430373966306463636662333431373936633837616336326461
 +38633139616339343865626630333531366138313761663330346231333131346535663761396233
 +35353036373530323636636335336539616433373461653866316138306632323038626266623264
 +6634
 +</code>
 +
 +Exécutez le playbook :
 +
 +<code>
 +[root@centos7 ~]# ansible-playbook vsftpd.yml --ask-vault-pass
 +Vault password: fenestros
 +[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 +
 +PLAY [ftp server install] *************************************************************************************************************************************************
 +
 +TASK [latest vsftpd version] **********************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [latest firewalld version] *******************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [vsftpd] *************************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [firewalld] **********************************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [firewalld allows ftp] ***********************************************************************************************************************************************
 +ok: [localhost]
 +
 +TASK [Create_FTP_users] ***************************************************************************************************************************************************
 +changed: [localhost] => (item={u'username': u'mike', u'password': u'toto'})
 +changed: [localhost] => (item={u'username': u'bob', u'password': u'tata'})
 +
 +PLAY RECAP ****************************************************************************************************************************************************************
 +localhost                  : ok=7    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 +</code>
 +
 +Notez que malgré le fait que le fichier **users.yml** soit crypté, les mots de passe des utilisateurs apparaissent en clair lors de l'exécution de la commande **ansible-playbook**. Pour palier à ce problème de sécurité, ajoutez **no_log: True** à la fin du fichier **vsftpd.yml** :
 +
 +
 +<code>
 +[root@centos7 ~]# vi vsftpd.yml
 +[root@centos7 ~]# cat vsftpd.yml
 +...
 +    - name: Create_FTP_users
 +      user:
 +        name: "{{ item.username }}" # pas d'instruction name
 +        password: "{{ item.password | password_hash('sha512') }}" # erreur de guillement
 +      with_items: "{{ ftp_users }}" # erreur d'indentation
 +      no_log: True
 +</code>
 +
 +De cette façon lors de l'exécution de la commande **ansible-playbook** vous obtiendrez :
 +
 +<code>
 +[root@centos7 ~]# ansible-playbook vsftpd.yml --ask-vault-pass
 +Vault password: fenestros
 +[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 +...
 +TASK [Create_FTP_users] ***************************************************************************************************************************************************
 +changed: [localhost] => (item=None)
 +changed: [localhost] => (item=None)
 +
 +PLAY RECAP ****************************************************************************************************************************************************************
 +localhost                  : ok=7    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 
 +</code>
 +
 +[/isauth]
  
 ----- -----
  
-Copyright © 2022 Hugh Norris.+Copyright © 2024 Hugh Norris.
Menu