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:debian:6:avance:l130:part3 [2020/02/13 15:11] adminelearning:workbooks:debian:6:avance:l130:part3 [2023/08/25 01:29] (Version actuelle) admin
Ligne 1: Ligne 1:
 ~~PDF:LANDSCAPE~~ ~~PDF:LANDSCAPE~~
 +
 +Version - **2023.01**
  
 Dernière mise-à-jour : ~~LASTMOD~~ Dernière mise-à-jour : ~~LASTMOD~~
  
-====== DOF503 - Rôles, Gabarits et Hiérarchie des Variables======+====== LCF803 - Rôles, GabaritsVariables et Facts====== 
 + 
 +=====Contenu du Module===== 
 + 
 +  * **LCF803 - Rôles, Gabarits, Variables et Facts** 
 +    * Contenu du Module 
 +    * LAB #1 - Dépendances de Rôles 
 +    * LAB #2 - Utilisation des Gabarits 
 +      * 2.1 - Variables 
 +      * 2.2 - Gabarits Conditionnels 
 +      * 2.3 - Boucles 
 +      * 2.4 - Macros 
 +      * 2.5 - Filtres 
 +        * 2.5.1 - Default 
 +        * 2.5.2 - Join 
 +        * 2.5.3 - Map 
 +      * 2.6 - Gabarits Parent - Enfants 
 +        * 2.6.1 - Le Gabarit Parent 
 +        * 2.6.2 - Le Gabarit Enfant 
 +    * 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 #- Dépendances de Rôles=====+=====LAB #- Dépendances de Rôles=====
  
 Afin de comprendre le fonctionnement des dépendances entre les Rôles vous allez étudier l'exemple de l'installation d'Apache Tomcat. Apache Tomcat est un serveur d'applications Java et par conséquent nécessite à ce que Java soit installé. Afin de comprendre le fonctionnement des dépendances entre les Rôles vous allez étudier l'exemple de l'installation d'Apache Tomcat. Apache Tomcat est un serveur d'applications Java et par conséquent nécessite à ce que Java soit installé.
Ligne 12: Ligne 39:
  
 <code> <code>
-trainee@ansible:~$ mkdir /home/trainee/.ansible/roles/exemple01.java/ +[trainee@centos8 ~]$ mkdir /home/trainee/.ansible/roles/exemple01.java/ 
-trainee@ansible:~$ cd /home/trainee/.ansible/roles/exemple01.java/ +[trainee@centos8 ~]$ cd /home/trainee/.ansible/roles/exemple01.java/ 
-trainee@ansible:~/.ansible/roles/exemple01.java$ mkdir defaults tasks templates +[trainee@centos8 exemple01.java]$ mkdir defaults tasks templates 
-trainee@ansible:~/.ansible/roles/exemple01.java$ +[trainee@centos8 exemple01.java]
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que dans ce Rôle nous n'avons besoin que des répertoires **defaults**, **tasks** et **templates**. **Important** : Notez que dans ce Rôle nous n'avons besoin que des répertoires **defaults**, **tasks** et **templates**.
 </WRAP> </WRAP>
Ligne 25: Ligne 52:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/exemple01.java$ vi /home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml +[trainee@centos8 exemple01.java]$ vi /home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml 
-trainee@ansible:~/.ansible/roles/exemple01.java$ cat /home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml+[trainee@centos8 exemple01.java]$ cat /home/trainee/.ansible/roles/exemple01.java/tasks/main.yaml
 --- ---
 - name: install jre - name: install jre
Ligne 40: Ligne 67:
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que le paquet à installer n'est pas explicitement déclaré. Le paquet est référencé par le contenu de la variable **java_package**, elle-même déclarée dans le fichier **main.yaml** du sous-répertoire **defaults** du Rôle. Notez aussi l'utilisation d'un gabarit, appelé **template**, qui fournit le fichier **java.sh** qui doit être copié à l'emplacement **/etc/profile.d/** à partir du sous-répertoire **templates** du Rôle. **Important** : Notez que le paquet à installer n'est pas explicitement déclaré. Le paquet est référencé par le contenu de la variable **java_package**, elle-même déclarée dans le fichier **main.yaml** du sous-répertoire **defaults** du Rôle. Notez aussi l'utilisation d'un gabarit, appelé **template**, qui fournit le fichier **java.sh** qui doit être copié à l'emplacement **/etc/profile.d/** à partir du sous-répertoire **templates** du Rôle.
 </WRAP> </WRAP>
Ligne 47: Ligne 74:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/exemple01.java$ vi /home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml +[trainee@centos8 exemple01.java]$ vi /home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml 
-trainee@ansible:~/.ansible/roles/exemple01.java$ cat /home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml+[trainee@centos8 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 54: Ligne 81:
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez qu'ici sont déclarées deux variables : **java_home** et **java_package**. **Important** : Notez qu'ici sont déclarées deux variables : **java_home** et **java_package**.
 </WRAP> </WRAP>
Ligne 61: Ligne 88:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/exemple01.java$ touch /home/trainee/.ansible/roles/exemple01.java/templates/java.sh+[trainee@centos8 exemple01.java]$ touch /home/trainee/.ansible/roles/exemple01.java/templates/java.sh
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Ce fichier ne serait pas normalement vide. Par contre dans ce LAB, nous nous concentrons sur Ansible et seule la présence du fichier est nécessaire pour le bon fonctionnement du LAB. **Important** : Ce fichier ne serait pas normalement vide. Par contre dans ce LAB, nous nous concentrons sur Ansible et seule la présence du fichier est nécessaire pour le bon fonctionnement du LAB.
 </WRAP> </WRAP>
Ligne 71: Ligne 98:
  
 <code> <code>
-trainee@ansible:~$ mkdir /home/trainee/.ansible/roles/tomcat/ +[trainee@centos8 exemple01.java]$ mkdir /home/trainee/.ansible/roles/tomcat/ 
-trainee@ansible:~$ cd /home/trainee/.ansible/roles/tomcat/ +[trainee@centos8 exemple01.java]$ cd /home/trainee/.ansible/roles/tomcat/ 
-trainee@ansible:~/.ansible/roles/tomcat$ mkdir meta tasks+[trainee@centos8 tomcat]$ mkdir meta tasks
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que dans ce Rôle nous n'avons besoin que des répertoires **meta** et **tasks**. **Important** : Notez que dans ce Rôle nous n'avons besoin que des répertoires **meta** et **tasks**.
 </WRAP> </WRAP>
Ligne 83: Ligne 110:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/tomcat$ vi /home/trainee/.ansible/roles/tomcat/tasks/main.yaml +[trainee@centos8 tomcat]$ vi /home/trainee/.ansible/roles/tomcat/tasks/main.yaml 
-trainee@ansible:~/.ansible/roles/tomcat$ cat /home/trainee/.ansible/roles/tomcat/tasks/main.yaml+[trainee@centos8 tomcat]$ cat /home/trainee/.ansible/roles/tomcat/tasks/main.yaml
 --- ---
 - name: install tomcat - name: install tomcat
Ligne 93: Ligne 120:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/tomcat$ vi /home/trainee/.ansible/roles/tomcat/meta/main.yaml +[trainee@centos8 tomcat]$ vi /home/trainee/.ansible/roles/tomcat/meta/main.yaml 
-trainee@ansible:~/.ansible/roles/tomcat$ cat /home/trainee/.ansible/roles/tomcat/meta/main.yaml+[trainee@centos8 tomcat]$ cat /home/trainee/.ansible/roles/tomcat/meta/main.yaml
 --- ---
 dependencies: dependencies:
Ligne 100: Ligne 127:
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Ce fichier informe Ansible que le Rôle **tomcat** dépend du Rôle **exemple01.java**. **Important** : Ce fichier informe Ansible que le Rôle **tomcat** dépend du Rôle **exemple01.java**.
 </WRAP> </WRAP>
Ligne 107: Ligne 134:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/tomcat$ vi /home/trainee/.ansible/roles/playbook.yaml +[trainee@centos8 tomcat]$ vi /home/trainee/.ansible/roles/playbook.yaml 
-trainee@ansible:~/.ansible/roles/tomcat$ cat /home/trainee/.ansible/roles/playbook.yaml+[trainee@centos8 tomcat]$ cat /home/trainee/.ansible/roles/playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 116: Ligne 143:
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que dans le Play Book, nous appelons **uniquement** le Rôle **tomcat**. **Important** : Notez que dans le Play Book, nous appelons **uniquement** le Rôle **tomcat**.
 </WRAP> </WRAP>
Ligne 130: Ligne 157:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ tree+[trainee@centos8 roles]$ tree
 . .
 ├── exemple01.java ├── exemple01.java
-│   ├── defaults +│   ├── defaults 
-│   │   └── main.yaml +│   │   └── main.yaml 
-│   ├── tasks +│   ├── tasks 
-│   │   └── main.yaml +│   │   └── main.yaml 
-│   └── templates +│   └── templates 
-│       └── java.sh+│       └── java.sh
 ├── geerlingguy.java ├── geerlingguy.java
-│   ├── defaults +│   ├── defaults 
-│   │   └── main.yml +│   │   └── main.yml 
-│   ├── LICENSE +│   ├── LICENSE 
-│   ├── meta +│   ├── meta 
-│   │   └── main.yml +│   │   └── main.yml 
-│   ├── molecule +│   ├── molecule 
-│   │   └── default +│   │   └── default 
-│   │       ├── molecule.yml +│   │       ├── converge.yml 
-│   │       ├── playbook.yml +│   │       └── molecule.yml 
-│   │       ├── tests +│   ├── README.md 
-│   │       │   └── test_default.py +│   ├── tasks 
-│   │       └── yaml-lint.yml +│   │   ├── main.yml 
-│   ├── README.md +│   │   ├── setup-Debian.yml 
-│   ├── tasks +│   │   ├── setup-FreeBSD.yml 
-│   │   ├── main.yml +│   │   └── setup-RedHat.yml 
-│   │   ├── setup-Debian.yml +│   ├── templates 
-│   │   ├── setup-FreeBSD.yml +│   │   └── java_home.sh.j2 
-│   │   └── setup-RedHat.yml +│   └── vars 
-│   ├── templates +│       ├── Debian-10.yml 
-│   │   └── java_home.sh.j2 +│       ├── Debian-11.yml 
-│   └── vars +│       ├── Debian-8.yml 
-│       ├── Debian-8.yml +│       ├── Debian-9.yml 
-│       ├── Debian-9.yml +│       ├── Fedora.yml 
-│       ├── Fedora.yml +│       ├── FreeBSD.yml 
-│       ├── FreeBSD.yml +│       ├── RedHat-7.yml 
-│       ├── RedHat-6.yml +│       ├── RedHat-8.yml 
-│       ├── RedHat-7.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
 ├── inventory ├── inventory
 ├── playbook.yaml ├── playbook.yaml
 └── tomcat └── tomcat
     ├── meta     ├── meta
-    │   └── main.yaml+    │   └── main.yaml
     └── tasks     └── tasks
         └── main.yaml         └── main.yaml
  
-16 directories, 30 files+15 directories, 31 files
 </code> </code>
  
Ligne 185: Ligne 212:
    
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l web01+[trainee@centos8 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 +web01                      : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que le Rôle **exemple01.java** est traité **avant** le Rôle **tomcat**. **Important** : Notez que le Rôle **exemple01.java** est traité **avant** le Rôle **tomcat**.
 </WRAP> </WRAP>
Ligne 212: Ligne 239:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ssh web01+[trainee@centos8 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 222: Ligne 249:
 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 Jan 30 00:03:51 2019 from 10.0.2.+Last login: Wed Mar  9 13:49:26 2022 from 10.0.2.45
-trainee@web01:~$ java -version +
-openjdk version "1.8.0_181" +
-OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13) +
-OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)+
 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 2019-01-30 00:04:18 CET; 2min 31s ago+   Active: active (running) since Wed 2022-03-09 13:50:11 CET; 1min 13s ago
      Docs: man:systemd-sysv-generator(8)      Docs: man:systemd-sysv-generator(8)
    CGroup: /system.slice/tomcat8.service    CGroup: /system.slice/tomcat8.service
-           └─9133 /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+           └─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
 trainee@web01:~$ exit trainee@web01:~$ exit
 déconnexion déconnexion
 Connection to web01 closed. Connection to web01 closed.
 +[trainee@centos8 roles]$ 
 </code> </code>
  
Ligne 242: Ligne 266:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/tomcat/meta/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/tomcat/meta/main.yaml 
-trainee@ansible:~/.ansible/roles$ cat /home/trainee/.ansible/roles/tomcat/meta/main.yaml+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/tomcat/meta/main.yaml
 --- ---
 dependencies: dependencies:
-  - { role: exemple01.java, java_package: tree } +  - { role: exemple01.java, java_package: tree }  
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que cette fois-ci, la valeur de la variable **java_package** spécifiée dans le fichier **/home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml** est sur-chargée par la valeur **tree**. **Important** : Notez que cette fois-ci, la valeur de la variable **java_package** spécifiée dans le fichier **/home/trainee/.ansible/roles/exemple01.java/defaults/main.yaml** est sur-chargée par la valeur **tree**.
 </WRAP> </WRAP>
Ligne 256: Ligne 280:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l web02+[trainee@centos8 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  +web02                      : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
 </code> </code>
  
-=====LAB #9 - Utilisation des Gabarits=====+Vérifiez que la dépendance **tree** a été installée dans Web02 :
  
-====Variables====+<code> 
 +[trainee@centos8 roles]$ ssh web02 
 +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 
 + 
 +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 13:53:57 2022 from 10.0.2.45 
 +trainee@web02:~$ which tree 
 +/usr/bin/tree 
 +trainee@web02:~$ exit 
 +déconnexion 
 +Connection to web02 closed. 
 +[trainee@centos8 roles]$ ssh web03 
 +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> 
 + 
 +=====LAB #2 - Utilisation des Gabarits===== 
 + 
 +====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>
 **Important** : La documentation des gabarits se trouvent à cette adresse: **[[https://docs.ansible.com/ansible/latest/modules/template_module.html]]**. **Important** : La documentation des gabarits se trouvent à cette adresse: **[[https://docs.ansible.com/ansible/latest/modules/template_module.html]]**.
 </WRAP> </WRAP>
Ligne 291: Ligne 352:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ mkdir /home/trainee/.ansible/roles/haproxy/ +[trainee@centos8 roles]$ mkdir /home/trainee/.ansible/roles/haproxy/ 
-trainee@ansible:~$ cd /home/trainee/.ansible/roles/haproxy/ +[trainee@centos8 roles]$ cd /home/trainee/.ansible/roles/haproxy/ 
-trainee@ansible:~/.ansible/roles/haproxy$ mkdir defaults handlers tasks templates+[trainee@centos8 haproxy]$ mkdir defaults handlers tasks templates 
 +[trainee@centos8 haproxy]$
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que dans ce Rôle nous n'avons besoin que des répertoires **defaults**, **handlers**, **tasks** et **templates**. **Important** : Notez que dans ce Rôle nous n'avons besoin que des répertoires **defaults**, **handlers**, **tasks** et **templates**.
 </WRAP> </WRAP>
Ligne 303: Ligne 365:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/haproxy$ vi /home/trainee/.ansible/roles/haproxy/tasks/main.yaml +[trainee@centos8 haproxy]$ vi /home/trainee/.ansible/roles/haproxy/tasks/main.yaml 
-trainee@ansible:~/.ansible/roles/haproxy$ cat /home/trainee/.ansible/roles/haproxy/tasks/main.yaml+[trainee@centos8 haproxy]$ cat /home/trainee/.ansible/roles/haproxy/tasks/main.yaml
 ---  --- 
 - name: install - name: install
Ligne 322: Ligne 384:
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que l'installation fait appel à un gabarit suivi par un **Handler** qui s'appelle **reload haproxy**. **Important** : Notez que l'installation fait appel à un gabarit suivi par un **Handler** qui s'appelle **reload haproxy**.
 </WRAP> </WRAP>
Ligne 329: Ligne 391:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/haproxy$ vi /home/trainee/.ansible/roles/haproxy/handlers/main.yaml +[trainee@centos8 haproxy]$ vi /home/trainee/.ansible/roles/haproxy/handlers/main.yaml 
-trainee@ansible:~/.ansible/roles/haproxy$ cat /home/trainee/.ansible/roles/haproxy/handlers/main.yaml+[trainee@centos8 haproxy]$ cat /home/trainee/.ansible/roles/haproxy/handlers/main.yaml
 --- ---
 - name: reload haproxy - name: reload haproxy
Ligne 339: Ligne 401:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/haproxy$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +[trainee@centos8 haproxy]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-trainee@ansible:~/.ansible/roles/haproxy$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+[trainee@centos8 haproxy]$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
 global global
- log /dev/log local0 +        log /dev/log    local0 
- log /dev/log local1 notice +        log /dev/log    local1 notice 
- chroot /var/lib/haproxy +        chroot /var/lib/haproxy 
- stats socket /run/haproxy/admin.sock mode 660 level admin +        stats socket /run/haproxy/admin.sock mode 660 level admin 
- stats timeout 30s +        stats timeout 30s 
- user haproxy +        user haproxy 
- group haproxy +        group haproxy 
- daemon+        daemon
  
- # Default SSL material locations +        # Default SSL material locations 
- ca-base /etc/ssl/certs +        ca-base /etc/ssl/certs 
- crt-base /etc/ssl/private+        crt-base /etc/ssl/private
  
- # Default ciphers to use on SSL-enabled listening sockets. +        # Default ciphers to use on SSL-enabled listening sockets. 
- # For more information, see ciphers(1SSL). This list is from: +        # For more information, see ciphers(1SSL). This list is from: 
- #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ +        #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ 
- # An alternative list with additional directives can be obtained from +        # An alternative list with additional directives can be obtained from 
- #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy +        #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy 
- ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS +        ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS 
- ssl-default-bind-options no-sslv3+        ssl-default-bind-options no-sslv3
  
 defaults defaults
- log global +        log     global 
- mode http +        mode    http 
- option httplog +        option  httplog 
- option dontlognull+        option  dontlognull
         timeout connect 5000         timeout connect 5000
         timeout client  50000         timeout client  50000
         timeout server  50000         timeout server  50000
- errorfile 400 /etc/haproxy/errors/400.http +        errorfile 400 /etc/haproxy/errors/400.http 
- errorfile 403 /etc/haproxy/errors/403.http +        errorfile 403 /etc/haproxy/errors/403.http 
- errorfile 408 /etc/haproxy/errors/408.http +        errorfile 408 /etc/haproxy/errors/408.http 
- errorfile 500 /etc/haproxy/errors/500.http +        errorfile 500 /etc/haproxy/errors/500.http 
- errorfile 502 /etc/haproxy/errors/502.http +        errorfile 502 /etc/haproxy/errors/502.http 
- errorfile 503 /etc/haproxy/errors/503.http +        errorfile 503 /etc/haproxy/errors/503.http 
- errorfile 504 /etc/haproxy/errors/504.http+        errorfile 504 /etc/haproxy/errors/504.http
  
 frontend haproxy frontend haproxy
Ligne 392: Ligne 454:
  
 backend dotcms backend dotcms
-    server web02 10.0.2.12:8080 check +    server web02 10.0.2.55:8080 check 
-    server web03 10.0.2.13:8080 check+    server web03 10.0.2.56:8080 check
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez l'utilisation de deux variables Ansible dans ce fichier - **%%{{ haproxy_listen_address }}%%** et **%%{{haproxy_listen_port}}%%**. **Important** : Notez l'utilisation de deux variables Ansible dans ce fichier - **%%{{ haproxy_listen_address }}%%** et **%%{{haproxy_listen_port}}%%**.
 </WRAP> </WRAP>
Ligne 403: Ligne 465:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/haproxy$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +[trainee@centos8 haproxy]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-trainee@ansible:~/.ansible/roles/haproxy$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+[trainee@centos8 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 414: Ligne 476:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles/haproxy$ cd .. +[trainee@centos8 haproxy]$ cd .. 
-trainee@ansible:~/.ansible/roles$ vi playbook.yaml  +[trainee@centos8 roles]$ vi playbook.yaml 
-trainee@ansible:~/.ansible/roles$ cat playbook.yaml +[trainee@centos8 roles]$ cat playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 427: Ligne 489:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage+[trainee@centos8 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]+changed: [web04]
  
-TASK [haproxy : service] ************************************************************************************************************************************************+TASK [haproxy : service] *****************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
  
-PLAY RECAP ************************************************************************************************************************************************************** +RUNNING HANDLER [haproxy : reload haproxy] *********************************************************************************************************************************************************************** 
-web04                      : ok=   changed=   unreachable=0    failed=0 +changed: [web04] 
 + 
 +PLAY RECAP ******************************************************************************************************************************************************************************************************* 
 +web04                      : ok=   changed=   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 </code> </code>
  
Ligne 450: Ligne 515:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ssh web04+[trainee@centos8 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 460: Ligne 525:
 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 Jan 30 01:47:12 2019 from 10.0.2.9+Last login: Wed Mar  9 15:23:48 2022 from 10.0.2.45 
 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 Tue 2019-01-29 17:34:25 CET; 8h ago+   Active: active (running) since Wed 2022-03-09 12:03:47 CET; 3h 20min 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
- Main PID: 2444 (haproxy-systemd)+  Process: 9089 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) 
 + Main PID: 5394 (haproxy-systemd)
     Tasks: 3 (limit: 4915)     Tasks: 3 (limit: 4915)
    CGroup: /system.slice/haproxy.service    CGroup: /system.slice/haproxy.service
-           ├─2444 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid +           ├─5394 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid 
-           ├─2447 /usr/sbin/haproxy-master +           ├─9091 /usr/sbin/haproxy-master 
-           └─2449 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds+           └─9093 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds -sf 5400 
 trainee@web04:~$ cat /etc/haproxy/haproxy.cfg trainee@web04:~$ cat /etc/haproxy/haproxy.cfg
 global global
- log /dev/log local0 +        log /dev/log    local0 
- log /dev/log local1 notice +        log /dev/log    local1 notice 
- chroot /var/lib/haproxy +        chroot /var/lib/haproxy 
- stats socket /run/haproxy/admin.sock mode 660 level admin +        stats socket /run/haproxy/admin.sock mode 660 level admin 
- stats timeout 30s +        stats timeout 30s 
- user haproxy +        user haproxy 
- group haproxy +        group haproxy 
- daemon+        daemon
  
- # Default SSL material locations +        # Default SSL material locations 
- ca-base /etc/ssl/certs +        ca-base /etc/ssl/certs 
- crt-base /etc/ssl/private+        crt-base /etc/ssl/private
  
- # Default ciphers to use on SSL-enabled listening sockets. +        # Default ciphers to use on SSL-enabled listening sockets. 
- # For more information, see ciphers(1SSL). This list is from: +        # For more information, see ciphers(1SSL). This list is from: 
- #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ +        #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ 
- # An alternative list with additional directives can be obtained from +        # An alternative list with additional directives can be obtained from 
- #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy +        #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy 
- ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS +        ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS 
- ssl-default-bind-options no-sslv3+        ssl-default-bind-options no-sslv3
  
 defaults defaults
- log global +        log     global 
- mode http +        mode    http 
- option httplog +        option  httplog 
- option dontlognull+        option  dontlognull
         timeout connect 5000         timeout connect 5000
         timeout client  50000         timeout client  50000
         timeout server  50000         timeout server  50000
- errorfile 400 /etc/haproxy/errors/400.http +        errorfile 400 /etc/haproxy/errors/400.http 
- errorfile 403 /etc/haproxy/errors/403.http +        errorfile 403 /etc/haproxy/errors/403.http 
- errorfile 408 /etc/haproxy/errors/408.http +        errorfile 408 /etc/haproxy/errors/408.http 
- errorfile 500 /etc/haproxy/errors/500.http +        errorfile 500 /etc/haproxy/errors/500.http 
- errorfile 502 /etc/haproxy/errors/502.http +        errorfile 502 /etc/haproxy/errors/502.http 
- errorfile 503 /etc/haproxy/errors/503.http +        errorfile 503 /etc/haproxy/errors/503.http 
- errorfile 504 /etc/haproxy/errors/504.http+        errorfile 504 /etc/haproxy/errors/504.http
  
 frontend haproxy frontend haproxy
Ligne 525: Ligne 594:
  
 backend dotcms backend dotcms
-    server web02 10.0.2.12:8080 check +    server web02 10.0.2.55:8080 check 
-    server web03 10.0.2.13: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]$ 
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que les valeurs des variables spécifiées dans le fichier **/home/trainee/.ansible/roles/haproxy/defaults/main.yaml** ont été injectées à la place des variables **%%{{ haproxy_listen_address }}%%** et **%%{{haproxy_listen_port}}%%**. **Important** : Notez que les valeurs des variables spécifiées dans le fichier **/home/trainee/.ansible/roles/haproxy/defaults/main.yaml** ont été injectées à la place des variables **%%{{ haproxy_listen_address }}%%** et **%%{{haproxy_listen_port}}%%**.
 </WRAP> </WRAP>
  
-====Gabarits Conditionnels====+====2.2 - Gabarits Conditionnels====
  
 Les gabarits peuvent être configurés d'une manière conditionnelle afin de produire des résultats différents en fonction de la valeur d'une variable. Afin de comprendre le fonctionnement des gabarits conditionnels vous allez modifier l'exemple de l'installation d'HAProxy sur la machine **Web04**. Les gabarits peuvent être configurés d'une manière conditionnelle afin de produire des résultats différents en fonction de la valeur d'une variable. Afin de comprendre le fonctionnement des gabarits conditionnels vous allez modifier l'exemple de l'installation d'HAProxy sur la machine **Web04**.
Ligne 543: Ligne 614:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-trainee@ansible:~/.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@ansible:~/.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 561: Ligne 631:
  
 backend dotcms backend dotcms
-    server web02 10.0.2.12:8080 check +    server web02 10.0.2.55:8080 check 
-    server web03 10.0.2.13:8080 check+    server web03 10.0.2.56:8080 check
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez la condition **%%{% if haproxy_stats %}%%** qui ne tiendra compte des quatre lignes jusqu'à la ligne **%%{% endif %}%%** que dans le cas où la valeur de la variable **haproxy_stats** est **True**. **Important** : Notez la condition **%%{% if haproxy_stats %}%%** qui ne tiendra compte des quatre lignes jusqu'à la ligne **%%{% endif %}%%** que dans le cas où la valeur de la variable **haproxy_stats** est **True**.
 </WRAP> </WRAP>
Ligne 572: Ligne 642:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-trainee@ansible:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+[trainee@centos8 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 581: Ligne 651:
 </code> </code>
  
-<WRAP center round important 60%+<WRAP center round important> 
-**Important** : Notez qu'Ansible teste si la variable est définie. Par conséquant la variable peut contenir la valeur **True**, **true** voire toute autre chaîne telle que **toto**.+**Important** : Notez qu'Ansible teste si la variable est définie. Par conséquent la variable peut contenir la valeur **True**, **true** voire toute autre chaîne telle que **toto**.
 </WRAP> </WRAP>
  
Ligne 588: Ligne 658:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage+[trainee@centos8 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   +web04                      : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  
 </code> </code>
  
Ligne 611: Ligne 681:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ssh web04+[trainee@centos8 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 621: Ligne 691:
 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 Jan 30 02:11:48 2019 from 10.0.2.9 +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
  
 frontend haproxy frontend haproxy
Ligne 638: Ligne 708:
  
 backend dotcms backend dotcms
-    server web02 10.0.2.12:8080 check +    server web02 10.0.2.55:8080 check 
-    server web03 10.0.2.13: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]$ 
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que les quatre lignes concernant les statistiques ont été incluses dans le fichier. **Important** : Notez que les quatre lignes concernant les statistiques ont été incluses dans le fichier.
 </WRAP> </WRAP>
Ligne 652: Ligne 723:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-trainee@ansible:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+[trainee@centos8 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 661: Ligne 732:
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez qu'Ansible teste si la variable n'est pas définie ou définie avec la valeur de **False** ou **false**. La valeur donc **haproxy_stats:** seule est considérée comme étant fausse.  **Important** : Notez qu'Ansible teste si la variable n'est pas définie ou définie avec la valeur de **False** ou **false**. La valeur donc **haproxy_stats:** seule est considérée comme étant fausse. 
 </WRAP> </WRAP>
Ligne 669: Ligne 740:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage+[trainee@centos8 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 +web04                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 
 </code> </code>
  
Ligne 695: Ligne 766:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ssh web04+[trainee@centos8 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 705: Ligne 776:
 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 Jan 30 02:14:56 2019 from 10.0.2.9 +Last login: Wed Mar  9 15:32:20 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 408 /etc/haproxy/errors/408.http +        errorfile 408 /etc/haproxy/errors/408.http 
- errorfile 500 /etc/haproxy/errors/500.http +        errorfile 500 /etc/haproxy/errors/500.http 
- errorfile 502 /etc/haproxy/errors/502.http +        errorfile 502 /etc/haproxy/errors/502.http 
- errorfile 503 /etc/haproxy/errors/503.http +        errorfile 503 /etc/haproxy/errors/503.http 
- errorfile 504 /etc/haproxy/errors/504.http+        errorfile 504 /etc/haproxy/errors/504.http
  
 frontend haproxy frontend haproxy
Ligne 722: Ligne 793:
  
 backend dotcms backend dotcms
-    server web02 10.0.2.12:8080 check +    server web02 10.0.2.55:8080 check 
-    server web03 10.0.2.13: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]$ 
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que les quatre lignes concernant les statistiques n'ont pas été incluses dans le fichier. **Important** : Notez que les quatre lignes concernant les statistiques n'ont pas été incluses dans le fichier.
 </WRAP> </WRAP>
Ligne 751: Ligne 823:
 </file> </file>
  
-====Boucles====+====2.3 - Boucles====
  
 Créez la variable **haproxy_backends** dans le fichier **/home/trainee/.ansible/roles/haproxy/defaults/main.yaml** : Créez la variable **haproxy_backends** dans le fichier **/home/trainee/.ansible/roles/haproxy/defaults/main.yaml** :
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-trainee@ansible:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+[trainee@centos8 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 764: Ligne 836:
 haproxy_stats: True  haproxy_stats: True 
 haproxy_backends: haproxy_backends:
-  - 'server web02 10.0.2.12:8080 check' +  - 'server web02 10.0.2.55:8080 check' 
-  - 'server web03 10.0.2.13:8080 check'+  - 'server web03 10.0.2.56:8080 check'
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que la variable **haproxy_backends** est une liste YAML. **Important** : Notez que la variable **haproxy_backends** est une liste YAML.
 </WRAP> </WRAP>
Ligne 775: Ligne 847:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-trainee@ansible:~/.ansible/roles$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+[trainee@centos8 roles]$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
     stats auth admin:admin     stats auth admin:admin
 {% endif %} {% endif %}
Ligne 792: Ligne 864:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-trainee@ansible:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+[trainee@centos8 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 801: Ligne 873:
 haproxy_backends: haproxy_backends:
   web02:   web02:
-    ip: 10.0.2.12+    ip: 10.0.2.55
   web03:   web03:
-    ip: 10.0.2.13+    ip: 10.0.2.56
 </code> </code>
  
Ligne 809: Ligne 881:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-trainee@ansible:~/.ansible/roles$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+[trainee@centos8 roles]$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
     stats auth admin:admin     stats auth admin:admin
 {% endif %} {% endif %}
Ligne 823: Ligne 895:
 </code> </code>
  
-====Macros====+====2.4 - Macros====
  
 Il est aussi possible d'utiliser un **macro** avec le dictionnaire : Il est aussi possible d'utiliser un **macro** avec le dictionnaire :
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi backend.j2 +[trainee@centos8 roles]$ vi backend.j2 
-trainee@ansible:~/.ansible/roles$ cat backend.j2+[trainee@centos8 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 837: Ligne 909:
 Il convient ensuite d'importer les valeurs dans le fichier **/home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg** : Il convient ensuite d'importer les valeurs dans le fichier **/home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg** :
  
-<file+<code
-...+[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
 +[trainee@centos8 roles]$ tail /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
 +{% endif %} 
 +    balance roundrobin 
 +    option httpclose 
 +    option forwardfor 
 {% import 'backend.j2' as backend %} {% import 'backend.j2' as backend %}
 backend dotcms backend dotcms
Ligne 844: Ligne 922:
 {{backend.backend(key, value.ip)}} {{backend.backend(key, value.ip)}}
 {% endfor %} {% endfor %}
-</file>+</code>
  
-====Filtres====+====2.5 - Filtres====
  
-===Default===+===2.5.1 - Default===
  
-Le filtre **default** permet de fournir une valeur par défaut pour une variable. Éditez le fichier **/home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg** et modifiez la variable **haproxy_listen_port** et la condition **haproxy_stats** :+Le filtre **default** permet de fournir une valeur par défaut pour une variable. Éditez le fichier **/home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg** et modifiez la variable **haproxy_listen_port**la condition **haproxy_stats** et la section backend dotcms :
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-trainee@ansible:~/.ansible/roles$ tail -n 17 /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+[trainee@centos8 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 877: Ligne 955:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/defaults/main.yaml 
-trainee@ansible:~/.ansible/roles$ cat /home/trainee/.ansible/roles/haproxy/defaults/main.yaml+[trainee@centos8 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 884: Ligne 962:
 haproxy_backends: haproxy_backends:
   web02:   web02:
-    ip: 10.0.2.12+    ip: 10.0.2.55
   web03:   web03:
-    ip: 10.0.2.13+    ip: 10.0.2.56
 </code> </code>
  
Ligne 892: Ligne 970:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage+[trainee@centos8 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 +web04                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
 </code> </code>
  
Ligne 918: Ligne 996:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ssh web04+[trainee@centos8 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 928: Ligne 1006:
 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 Jan 30 03:16:11 2019 from 10.0.2.9 +Last login: Wed Mar  9 15:48:45 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
  
 frontend haproxy frontend haproxy
Ligne 945: Ligne 1023:
  
 backend dotcms backend dotcms
-    server web02 10.0.2.12:8080 check +    server web02 10.0.2.55:8080 check 
-    server web03 10.0.2.13: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]$ 
 </code> </code>
  
-===Join===+===2.5.2 - Join===
  
 Le filtre **Join** : Le filtre **Join** :
Ligne 974: Ligne 1053:
 </file> </file>
  
-===Map===+===2.5.3 - Map===
  
 Le filtre **Map** : Le filtre **Map** :
Ligne 987: Ligne 1066:
 haproxy_backends: haproxy_backends:
   web02:   web02:
-    ip: 10.0.2.12+    ip: 10.0.2.55
   web03:   web03:
-    ip: 10.0.2.13+    ip: 10.0.2.56
 </file> </file>
  
Ligne 995: Ligne 1074:
  
 <file> <file>
-10.0.2.12,10.0.2.13+10.0.2.55,10.0.2.56
 </file> </file>
  
-====Gabarits Parent - Enfants====+====2.6 - Gabarits Parent - Enfants====
  
 HAProxy ne gère pas uniquement le protocole http. Il peut également gérer d'autres connexions TCP. Pour cette raison, il est intéressant de créer un gabarit générique pour HAProxy et un gabarit enfants par protocole.  HAProxy ne gère pas uniquement le protocole http. Il peut également gérer d'autres connexions TCP. Pour cette raison, il est intéressant de créer un gabarit générique pour HAProxy et un gabarit enfants par protocole. 
  
-===Le Gabarit Parent===+===2.6.1 - Le Gabarit Parent===
  
 Modifiez donc le fichier **/home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg** : Modifiez donc le fichier **/home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg** :
  
 <code> <code>
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg 
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.cfg
 global global
- log /dev/log local0 +        log /dev/log    local0 
- log /dev/log local1 notice +        log /dev/log    local1 notice 
- chroot /var/lib/haproxy +        chroot /var/lib/haproxy 
- stats socket /run/haproxy/admin.sock mode 660 level admin +        stats socket /run/haproxy/admin.sock mode 660 level admin 
- stats timeout 30s +        stats timeout 30s 
- user haproxy +        user haproxy 
- group haproxy +        group haproxy 
- daemon+        daemon
 {% block globals %} {% block globals %}
 {% endblock %} {% endblock %}
  
 defaults defaults
- log global +        log     global 
- option dontlognull+        option  dontlognull
         timeout connect 5000         timeout connect 5000
         timeout client  50000         timeout client  50000
Ligne 1032: Ligne 1111:
 {% block server %} {% block server %}
 {% endblock %} {% endblock %}
- 
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Ce gabarit ne contient que des directives générales. Les directives spécifiques au protocole http ont été remplacées par des **blocs** nommés **globals**, **defaults** et **server**. **Important** : Ce gabarit ne contient que des directives générales. Les directives spécifiques au protocole http ont été remplacées par des **blocs** nommés **globals**, **defaults** et **server**.
 </WRAP> </WRAP>
  
-===Le Gabarit Enfant===+===2.6.2 - Le Gabarit Enfant===
  
 Créez maintenant le gabarit **/home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg**, spécifique au protocole http : Créez maintenant le gabarit **/home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg**, spécifique au protocole http :
  
 <code> <code>
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg 
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/templates/haproxy.http.cfg
 {% extends 'haproxy.cfg' %} {% extends 'haproxy.cfg' %}
 {% block globals %} {% block globals %}
- ca-base /etc/ssl/certs +        ca-base /etc/ssl/certs 
- crt-base /etc/ssl/private +        crt-base /etc/ssl/private 
- ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS +        ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS 
- ssl-default-bind-options no-sslv3+        ssl-default-bind-options no-sslv3
 {% endblock %} {% endblock %}
 {% block defaults %} {% block defaults %}
- mode http +        mode    http 
- option httplog +        option  httplog 
- errorfile 400 /etc/haproxy/errors/400.http +        errorfile 400 /etc/haproxy/errors/400.http 
- errorfile 403 /etc/haproxy/errors/403.http +        errorfile 403 /etc/haproxy/errors/403.http 
- errorfile 408 /etc/haproxy/errors/408.http +        errorfile 408 /etc/haproxy/errors/408.http 
- errorfile 500 /etc/haproxy/errors/500.http +        errorfile 500 /etc/haproxy/errors/500.http 
- errorfile 502 /etc/haproxy/errors/502.http +        errorfile 502 /etc/haproxy/errors/502.http 
- errorfile 503 /etc/haproxy/errors/503.http +        errorfile 503 /etc/haproxy/errors/503.http 
- errorfile 504 /etc/haproxy/errors/504.http+        errorfile 504 /etc/haproxy/errors/504.http
 {% endblock %} {% endblock %}
 {% block server %} {% block server %}
Ligne 1086: Ligne 1164:
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que les **blocs** nommés **globals**, **defaults** et **server** contiennent les directives qui seront injectées dans le fichier **haproxy.cfg** aux emplacements des trois blocs respectifs. **Important** : Notez que les **blocs** nommés **globals**, **defaults** et **server** contiennent les directives qui seront injectées dans le fichier **haproxy.cfg** aux emplacements des trois blocs respectifs.
 </WRAP> </WRAP>
Ligne 1093: Ligne 1171:
  
 <code> <code>
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/haproxy/tasks/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/haproxy/tasks/main.yaml 
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/haproxy/tasks/main.yaml+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/haproxy/tasks/main.yaml
 --- ---
 - name: install - name: install
Ligne 1115: Ligne 1193:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -l equilibrage+[trainee@centos8 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 +web04                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  
 </code> </code>
  
Ligne 1141: Ligne 1219:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ssh web04+[trainee@centos8 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 1151: Ligne 1229:
 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 Jan 30 06:36:19 2019 from 10.0.2.9 +Last login: Wed Mar  9 15:54:56 2022 from 10.0.2.45 
-trainee@web04:~$ cat /etc/haproxy/haproxy.cfg +trainee@web04:~$ cat /etc/haproxy/haproxy.cfg
 global global
- log /dev/log local0 +        log /dev/log    local0 
- log /dev/log local1 notice +        log /dev/log    local1 notice 
- chroot /var/lib/haproxy +        chroot /var/lib/haproxy 
- stats socket /run/haproxy/admin.sock mode 660 level admin +        stats socket /run/haproxy/admin.sock mode 660 level admin 
- stats timeout 30s +        stats timeout 30s 
- user haproxy +        user haproxy 
- group haproxy +        group haproxy 
- daemon +        daemon 
- ca-base /etc/ssl/certs +        ca-base /etc/ssl/certs 
- crt-base /etc/ssl/private +        crt-base /etc/ssl/private 
- ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS +        ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS 
- ssl-default-bind-options no-sslv3+        ssl-default-bind-options no-sslv3
  
 defaults defaults
- log global +        log     global 
- option dontlognull+        option  dontlognull
         timeout connect 5000         timeout connect 5000
         timeout client  50000         timeout client  50000
         timeout server  50000         timeout server  50000
- mode http +        mode    http 
- option httplog +        option  httplog 
- errorfile 400 /etc/haproxy/errors/400.http +        errorfile 400 /etc/haproxy/errors/400.http 
- errorfile 403 /etc/haproxy/errors/403.http +        errorfile 403 /etc/haproxy/errors/403.http 
- errorfile 408 /etc/haproxy/errors/408.http +        errorfile 408 /etc/haproxy/errors/408.http 
- errorfile 500 /etc/haproxy/errors/500.http +        errorfile 500 /etc/haproxy/errors/500.http 
- errorfile 502 /etc/haproxy/errors/502.http +        errorfile 502 /etc/haproxy/errors/502.http 
- errorfile 503 /etc/haproxy/errors/503.http +        errorfile 503 /etc/haproxy/errors/503.http 
- errorfile 504 /etc/haproxy/errors/504.http+        errorfile 504 /etc/haproxy/errors/504.http
  
 frontend haproxy frontend haproxy
Ligne 1196: Ligne 1274:
  
 backend dotcms backend dotcms
-    server web02 10.0.2.12:8080 check +    server web02 10.0.2.55:8080 check 
-    server web03 10.0.2.13: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]$ 
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que les **blocs** nommés **globals**, **defaults** et **server** ont été renseignés. **Important** : Notez que les **blocs** nommés **globals**, **defaults** et **server** ont été renseignés.
 </WRAP> </WRAP>
  
-=====LAB #10 - Gestion de la Hiérarchie des Variables=====+=====LAB #- Gestion de la Hiérarchie des Variables=====
  
-Créez le Rôle **/home/trainee/.ansible/roles/debug** contenant les sous-répertoires **defaults** et **tasks** :+La hiérarchie de la prise en compte des variables par Ansible peut être illustrée par le diagramme suivant :
  
 <code> <code>
-trainee@ansible:~$ mkdir /home/trainee/.ansible/roles/debug +
-trainee@ansible:~$ mkdir /home/trainee/.ansible/roles/debug/defaults +├── 1.commandline 
-trainee@ansible:~$ mkdir /home/trainee/.ansible/roles/debug/tasks+└── roles 
 +    ├── 4.playbook.yaml 
 +    ├── debug 
 +    │   ├── defaults 
 +    │   │   └── 6.main.yaml 
 +    │   └── tasks 
 +    │       └── 7.main.yaml 
 +    ├── group_vars 
 +    │   ├── 3.groupname.yaml 
 +    │   └── 5.all.yaml 
 +    └── host_vars 
 +        └── 2.hostname.yaml 
 +</code>         
 + 
 +Pour illustrer cette hiérarchie, créez le Rôle **/home/trainee/.ansible/roles/debug** contenant les sous-répertoires **defaults** et **tasks** : 
 + 
 +<code> 
 +[trainee@centos8 roles]$ cd ../../ 
 +[trainee@centos8 ~]$ mkdir /home/trainee/.ansible/roles/debug 
 +[trainee@centos8 ~]$ mkdir /home/trainee/.ansible/roles/debug/defaults 
 +[trainee@centos8 ~]$ mkdir /home/trainee/.ansible/roles/debug/tasks 
 +[trainee@centos8 ~]$ 
 </code> </code>
  
Ligne 1220: Ligne 1320:
  
 <code> <code>
-trainee@ansible:~$ touch /home/trainee/.ansible/roles/debug/defaults/main.yaml +[trainee@centos8 ~]$ touch /home/trainee/.ansible/roles/debug/defaults/main.yaml 
-trainee@ansible:~$ touch  /home/trainee/.ansible/roles/debug/tasks/main.yaml+[trainee@centos8 ~]$ touch  /home/trainee/.ansible/roles/debug/tasks/main.yaml 
 +[trainee@centos8 ~]$ 
 </code> </code>
  
Ligne 1227: Ligne 1328:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ tree debug+[trainee@centos8 ~]$ cd .ansible/roles
 +[trainee@centos8 roles]$ tree debug
 debug debug
 ├── defaults ├── defaults
-│   └── main.yaml+│   └── main.yaml
 └── tasks └── tasks
     └── main.yaml     └── main.yaml
Ligne 1240: Ligne 1342:
  
 <code> <code>
-trainee@ansible:~$ mkdir /home/trainee/.ansible/roles/group_vars +[trainee@centos8 roles]$ mkdir /home/trainee/.ansible/roles/group_vars 
-trainee@ansible:~$ touch /home/trainee/.ansible/roles/group_vars/all.yaml+[trainee@centos8 roles]$ touch /home/trainee/.ansible/roles/group_vars/all.yaml 
 +[trainee@centos8 roles]$ 
 </code> </code>
  
Ligne 1247: Ligne 1350:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ tree group_vars/+[trainee@centos8 roles]$ tree group_vars/
 group_vars/ group_vars/
-── all.yaml+── all.yaml
  
 0 directories, 1 file 0 directories, 1 file
Ligne 1257: Ligne 1360:
  
 <code> <code>
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/debug/tasks/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/debug/tasks/main.yaml 
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/debug/tasks/main.yaml+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/debug/tasks/main.yaml
 --- ---
 - debug: - debug:
Ligne 1267: Ligne 1370:
  
 <code> <code>
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/playbook.yaml  +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/playbook.yaml 
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/playbook.yaml +[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 1278: Ligne 1381:
  
 <code> <code>
-trainee@ansible:~$ cd .ansible/roles/ +[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml+
  
-PLAY [all] **************************************************************************************************************************************************************+PLAY [all] *******************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] **************************************************************************************************************************************************+TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
 ok: [web04] ok: [web04]
-ok: [web02] 
 ok: [web03] ok: [web03]
 +ok: [web02]
 ok: [web01] ok: [web01]
  
-TASK [debug : debug] ****************************************************************************************************************************************************+TASK [debug : debug] *********************************************************************************************************************************************************************************************
 ok: [web01] => { ok: [web01] => {
     "msg": "Ce message est issu de roles/debug/tasks/main.yaml"     "msg": "Ce message est issu de roles/debug/tasks/main.yaml"
Ligne 1303: Ligne 1405:
 } }
  
-PLAY RECAP ************************************************************************************************************************************************************** +PLAY RECAP ******************************************************************************************************************************************************************************************************* 
-web01                      : ok=2    changed=0    unreachable=0    failed=0    +web01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web02                      : ok=2    changed=0    unreachable=0    failed=0    +web02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web03                      : ok=2    changed=0    unreachable=0    failed=0    +web03                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web04                      : ok=2    changed=0    unreachable=0    failed=0 +web04                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 </code> </code>
  
Ligne 1313: Ligne 1415:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/debug/defaults/main.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/debug/defaults/main.yaml 
-trainee@ansible:~/.ansible/roles$ cat /home/trainee/.ansible/roles/debug/defaults/main.yaml+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/debug/defaults/main.yaml
 --- ---
 endroit: 'roles/debug/defaults/main.yaml' endroit: 'roles/debug/defaults/main.yaml'
Ligne 1322: Ligne 1424:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml+[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml
  
-PLAY [all] **************************************************************************************************************************************************************+PLAY [all] *******************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] **************************************************************************************************************************************************+TASK [Gathering Facts] ******************************************************************************************************************************************************************************************* 
 +ok: [web03]
 ok: [web04] ok: [web04]
 +ok: [web02]
 ok: [web01] ok: [web01]
-ok: [web03] 
-ok: [web02] 
  
-TASK [debug : debug] **************************************************************************************************************************************************** +TASK [debug : debug] *********************************************************************************************************************************************************************************************
-ok: [web04] => { +
-    "msg": "Ce message est issu de roles/debug/defaults/main.yaml" +
-}+
 ok: [web01] => { ok: [web01] => {
     "msg": "Ce message est issu de roles/debug/defaults/main.yaml"     "msg": "Ce message est issu de roles/debug/defaults/main.yaml"
Ligne 1343: Ligne 1442:
 } }
 ok: [web03] => { ok: [web03] => {
 +    "msg": "Ce message est issu de roles/debug/defaults/main.yaml"
 +}
 +ok: [web04] => {
     "msg": "Ce message est issu de roles/debug/defaults/main.yaml"     "msg": "Ce message est issu de roles/debug/defaults/main.yaml"
 } }
  
-PLAY RECAP ************************************************************************************************************************************************************** +PLAY RECAP ******************************************************************************************************************************************************************************************************* 
-web01                      : ok=2    changed=0    unreachable=0    failed=0    +web01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web02                      : ok=2    changed=0    unreachable=0    failed=0    +web02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web03                      : ok=2    changed=0    unreachable=0    failed=0    +web03                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web04                      : ok=2    changed=0    unreachable=0    failed=0 +web04                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : La variable fixée dans **defaults/main.yaml** surcharge la variable fixée dans **tasks/main.yaml**. **Important** : La variable fixée dans **defaults/main.yaml** surcharge la variable fixée dans **tasks/main.yaml**.
 </WRAP> </WRAP>
Ligne 1360: Ligne 1462:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/group_vars/all.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/group_vars/all.yaml 
-trainee@ansible:~/.ansible/roles$ cat /home/trainee/.ansible/roles/group_vars/all.yaml+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/group_vars/all.yaml
 --- ---
 endroit: 'roles/group_vars/all.yaml' endroit: 'roles/group_vars/all.yaml'
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : La déclaration de la variable peut être faite dans **roles/group_vars/all** ou dans **roles/group_vars/all.yaml** ou dans un fichier *.yaml dans le répertoire **roles/group_vars/all/**. **Important** : La déclaration de la variable peut être faite dans **roles/group_vars/all** ou dans **roles/group_vars/all.yaml** ou dans un fichier *.yaml dans le répertoire **roles/group_vars/all/**.
 </WRAP> </WRAP>
Ligne 1373: Ligne 1475:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi /home/trainee/.ansible/roles/group_vars/all.yaml +[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml+
  
-PLAY [all] **************************************************************************************************************************************************************+PLAY [all] *******************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] ************************************************************************************************************************************************** +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
-ok: [web02] +
-ok: [web01]+
 ok: [web04] ok: [web04]
 ok: [web03] ok: [web03]
 +ok: [web01]
 +ok: [web02]
  
-TASK [debug : debug] ****************************************************************************************************************************************************+TASK [debug : debug] *********************************************************************************************************************************************************************************************
 ok: [web01] => { ok: [web01] => {
-    "msg": "Ce message est issu de roles/group_vars/all.yaml" 
-} 
-ok: [web04] => { 
     "msg": "Ce message est issu de roles/group_vars/all.yaml"     "msg": "Ce message est issu de roles/group_vars/all.yaml"
 } }
Ligne 1395: Ligne 1493:
 } }
 ok: [web03] => { ok: [web03] => {
 +    "msg": "Ce message est issu de roles/group_vars/all.yaml"
 +}
 +ok: [web04] => {
     "msg": "Ce message est issu de roles/group_vars/all.yaml"     "msg": "Ce message est issu de roles/group_vars/all.yaml"
 } }
  
-PLAY RECAP ************************************************************************************************************************************************************** +PLAY RECAP ******************************************************************************************************************************************************************************************************* 
-web01                      : ok=2    changed=0    unreachable=0    failed=0    +web01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web02                      : ok=2    changed=0    unreachable=0    failed=0    +web02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web03                      : ok=2    changed=0    unreachable=0    failed=0    +web03                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web04                      : ok=2    changed=0    unreachable=0    failed=0 +web04                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : La variable fixée dans **group_vars/all.yaml** surcharge la variable fixée dans **defaults/main.yaml** qui surcharge la variable fixée dans **tasks/main.yaml**. **Important** : La variable fixée dans **group_vars/all.yaml** surcharge la variable fixée dans **defaults/main.yaml** qui surcharge la variable fixée dans **tasks/main.yaml**.
 </WRAP> </WRAP>
Ligne 1412: Ligne 1513:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi playbook.yaml  +[trainee@centos8 roles]$ vi playbook.yaml 
-trainee@ansible:~/.ansible/roles$ cat playbook.yaml +[trainee@centos8 roles]$ cat playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 1423: Ligne 1524:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml+[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml
  
-PLAY [all] **************************************************************************************************************************************************************+PLAY [all] *******************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] **************************************************************************************************************************************************+TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
 ok: [web02] ok: [web02]
-ok: [web04] 
 ok: [web03] ok: [web03]
 ok: [web01] ok: [web01]
 +ok: [web04]
  
-TASK [debug : debug] ****************************************************************************************************************************************************+TASK [debug : debug] ********************************************************************************************************************************************************************************************* 
 +ok: [web01] => { 
 +    "msg": "Ce message est issu de playbook.yaml" 
 +}
 ok: [web02] => { ok: [web02] => {
     "msg": "Ce message est issu de playbook.yaml"     "msg": "Ce message est issu de playbook.yaml"
 } }
 ok: [web03] => { ok: [web03] => {
-    "msg": "Ce message est issu de playbook.yaml" 
-} 
-ok: [web01] => { 
     "msg": "Ce message est issu de playbook.yaml"     "msg": "Ce message est issu de playbook.yaml"
 } }
Ligne 1447: Ligne 1548:
 } }
  
-PLAY RECAP ************************************************************************************************************************************************************** +PLAY RECAP ******************************************************************************************************************************************************************************************************* 
-web01                      : ok=2    changed=0    unreachable=0    failed=0    +web01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web02                      : ok=2    changed=0    unreachable=0    failed=0    +web02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web03                      : ok=2    changed=0    unreachable=0    failed=0    +web03                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web04                      : ok=2    changed=0    unreachable=0    failed=0+web04                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : La variable fixée dans **playbook.yaml** surcharge la variable fixée dans **group_vars/all.yaml** qui surcharge la variable fixée dans **defaults/main.yaml** qui surcharge la variable fixée dans **tasks/main.yaml**. **Important** : La variable fixée dans **playbook.yaml** surcharge la variable fixée dans **group_vars/all.yaml** qui surcharge la variable fixée dans **defaults/main.yaml** qui surcharge la variable fixée dans **tasks/main.yaml**.
-</WRAP> 
- 
-Exécutez la commande **ansible-playbook** en définissant la valeur de la variable **endroit** sur la ligne de commande : 
- 
-<code> 
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml -e 'endroit="la ligne de commande"' 
- 
-PLAY [all] ************************************************************************************************************************************************************** 
- 
-TASK [Gathering Facts] ************************************************************************************************************************************************** 
-ok: [web01] 
-ok: [web04] 
-ok: [web03] 
-ok: [web02] 
- 
-TASK [debug : debug] **************************************************************************************************************************************************** 
-ok: [web04] => { 
-    "msg": "Ce message est issu de la ligne de commande" 
-} 
-ok: [web01] => { 
-    "msg": "Ce message est issu de la ligne de commande" 
-} 
-ok: [web02] => { 
-    "msg": "Ce message est issu de la ligne de commande" 
-} 
-ok: [web03] => { 
-    "msg": "Ce message est issu de la ligne de commande" 
-} 
- 
-PLAY RECAP ************************************************************************************************************************************************************** 
-web01                      : ok=2    changed=0    unreachable=0    failed=0    
-web02                      : ok=2    changed=0    unreachable=0    failed=0    
-web03                      : ok=2    changed=0    unreachable=0    failed=0    
-web04                      : ok=2    changed=0    unreachable=0    failed=0  
-</code> 
- 
-<WRAP center round important 60%> 
-**Important** : La variable fixée dans sur la **ligne de commande** surcharge la variable fixée dans **playbook.yaml** qui surcharge la variable fixée dans **group_vars/all.yaml** qui surcharge la variable fixée dans **defaults/main.yaml** qui surcharge la variable fixée dans **tasks/main.yaml**. 
 </WRAP> </WRAP>
  
Ligne 1499: Ligne 1562:
  
 <code> <code>
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/group_vars/group1.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/group_vars/group1.yaml 
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/group_vars/group1.yaml+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/group_vars/group1.yaml
 --- ---
 endroit: 'group_vars/group1.yaml' endroit: 'group_vars/group1.yaml'
Ligne 1508: Ligne 1571:
  
 <code> <code>
-trainee@ansible:~$ mkdir /home/trainee/.ansible/roles/host_vars +[trainee@centos8 roles]$ mkdir /home/trainee/.ansible/roles/host_vars 
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/host_vars/localhost.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/host_vars/localhost.yaml 
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/host_vars/localhost.yaml+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/host_vars/localhost.yaml
 --- ---
 # endroit: 'host_vars/localhost.yaml' # endroit: 'host_vars/localhost.yaml'
Ligne 1518: Ligne 1581:
  
 <code> <code>
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/playbook.yaml +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/playbook.yaml 
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/playbook.yaml+[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/playbook.yaml
 --- ---
 - hosts: all - hosts: all
Ligne 1529: Ligne 1592:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi inventory +[trainee@centos8 roles]$ vi inventory 
-trainee@ansible:~/.ansible/roles$ cat inventory+[trainee@centos8 roles]$ cat inventory
 localhost ansible_connection=local localhost ansible_connection=local
  
Ligne 1555: Ligne 1618:
  
 <code> <code>
-trainee@ansible:~$ cd /home/trainee/.ansible/roles/ +[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml+
  
-PLAY [all] **************************************************************************************************************************************************************+PLAY [all] *******************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] ************************************************************************************************************************************************** +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
-ok: [web03] +
-ok: [web01]+
 ok: [web04] ok: [web04]
-ok: [localhost]+ok: [web01]
 ok: [web02] ok: [web02]
 +ok: [web03]
 +ok: [localhost]
  
-TASK [debug : debug] ****************************************************************************************************************************************************+TASK [debug : debug] *********************************************************************************************************************************************************************************************
 ok: [localhost] => { ok: [localhost] => {
 +    "msg": "Ce message est issu de roles/group_vars/all.yaml"
 +}
 +ok: [web01] => {
     "msg": "Ce message est issu de roles/group_vars/all.yaml"     "msg": "Ce message est issu de roles/group_vars/all.yaml"
 } }
Ligne 1575: Ligne 1640:
 } }
 ok: [web03] => { ok: [web03] => {
-    "msg": "Ce message est issu de roles/group_vars/all.yaml" 
-} 
-ok: [web01] => { 
     "msg": "Ce message est issu de roles/group_vars/all.yaml"     "msg": "Ce message est issu de roles/group_vars/all.yaml"
 } }
Ligne 1584: Ligne 1646:
 } }
  
-PLAY RECAP ************************************************************************************************************************************************************** +PLAY RECAP ******************************************************************************************************************************************************************************************************* 
-localhost                  : ok=2    changed=0    unreachable=0    failed=0    +localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web01                      : ok=2    changed=0    unreachable=0    failed=0    +web01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web02                      : ok=2    changed=0    unreachable=0    failed=0   +web02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web03                      : ok=2    changed=0    unreachable=0    failed=0    +web03                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web04                      : ok=2    changed=0    unreachable=0    failed=0+web04                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : Notez que la valeur de la variable **endroit** spécifiée dans le fichier **group_vars/all.yaml** s'applique à tous les groupes **et** à tous les hôtes. **Important** : Notez que la valeur de la variable **endroit** spécifiée dans le fichier **group_vars/all.yaml** s'applique à tous les groupes **et** à tous les hôtes.
 </WRAP> </WRAP>
Ligne 1599: Ligne 1661:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ vi inventory +[trainee@centos8 roles]$ vi inventory 
-trainee@ansible:~/.ansible/roles$ cat inventory+[trainee@centos8 roles]$ cat inventory
 [group1] [group1]
 localhost ansible_connection=local localhost ansible_connection=local
Ligne 1626: Ligne 1688:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml+[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml
  
-PLAY [all] **************************************************************************************************************************************************************+PLAY [all] *******************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] ************************************************************************************************************************************************** +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
-ok: [web04] +
-ok: [web02]+
 ok: [web03] ok: [web03]
 ok: [web01] ok: [web01]
 +ok: [web02]
 +ok: [web04]
 ok: [localhost] ok: [localhost]
  
-TASK [debug : debug] ****************************************************************************************************************************************************+TASK [debug : debug] *********************************************************************************************************************************************************************************************
 ok: [localhost] => { ok: [localhost] => {
     "msg": "Ce message est issu de group_vars/group1.yaml"     "msg": "Ce message est issu de group_vars/group1.yaml"
 +}
 +ok: [web01] => {
 +    "msg": "Ce message est issu de roles/group_vars/all.yaml"
 } }
 ok: [web02] => { ok: [web02] => {
Ligne 1648: Ligne 1713:
 } }
 ok: [web04] => { ok: [web04] => {
-    "msg": "Ce message est issu de roles/group_vars/all.yaml" 
-} 
-ok: [web01] => { 
     "msg": "Ce message est issu de roles/group_vars/all.yaml"     "msg": "Ce message est issu de roles/group_vars/all.yaml"
 } }
  
-PLAY RECAP ************************************************************************************************************************************************************** +PLAY RECAP ******************************************************************************************************************************************************************************************************* 
-localhost                  : ok=2    changed=0    unreachable=0    failed=0    +localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web01                      : ok=2    changed=0    unreachable=0    failed=0    +web01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web02                      : ok=2    changed=0    unreachable=0    failed=0    +web02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web03                      : ok=2    changed=0    unreachable=0    failed=0    +web03                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web04                      : ok=2    changed=0    unreachable=0    failed=0 +web04                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 
 </code> </code>
  
-<WRAP center round important 60%>+<WRAP center round important>
 **Important** : La variable fixée dans **group_vars/group1.yaml** surcharge la variable fixée dans **group_vars/all.yaml**. **Important** : La variable fixée dans **group_vars/group1.yaml** surcharge la variable fixée dans **group_vars/all.yaml**.
 </WRAP> </WRAP>
Ligne 1669: Ligne 1731:
  
 <code> <code>
-trainee@ansible:~$ mkdir /home/trainee/.ansible/roles/host_vars +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/host_vars/localhost.yaml 
-trainee@ansible:~$ vi /home/trainee/.ansible/roles/host_vars/localhost.yaml +[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/host_vars/localhost.yaml
-trainee@ansible:~$ cat /home/trainee/.ansible/roles/host_vars/localhost.yaml+
 --- ---
 endroit: 'host_vars/localhost.yaml' endroit: 'host_vars/localhost.yaml'
Ligne 1679: Ligne 1740:
  
 <code> <code>
-trainee@ansible:~/.ansible/roles$ ansible-playbook -i inventory playbook.yaml+[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml
  
-PLAY [all] **************************************************************************************************************************************************************+PLAY [all] *******************************************************************************************************************************************************************************************************
  
-TASK [Gathering Facts] ************************************************************************************************************************************************** +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
-ok: [web01]+
 ok: [web02] ok: [web02]
-ok: [web04] 
 ok: [web03] ok: [web03]
 +ok: [web01]
 +ok: [web04]
 ok: [localhost] ok: [localhost]
  
-TASK [debug : debug] ****************************************************************************************************************************************************+TASK [debug : debug] *********************************************************************************************************************************************************************************************
 ok: [localhost] => { ok: [localhost] => {
     "msg": "Ce message est issu de host_vars/localhost.yaml"     "msg": "Ce message est issu de host_vars/localhost.yaml"
 +}
 +ok: [web01] => {
 +    "msg": "Ce message est issu de roles/group_vars/all.yaml"
 } }
 ok: [web02] => { ok: [web02] => {
Ligne 1702: Ligne 1766:
 ok: [web04] => { ok: [web04] => {
     "msg": "Ce message est issu de roles/group_vars/all.yaml"     "msg": "Ce message est issu de roles/group_vars/all.yaml"
 +}
 +
 +PLAY RECAP *******************************************************************************************************************************************************************************************************
 +localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 +web01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 +web02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 +web03                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
 +web04                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
 +</code>
 +
 +<WRAP center round important>
 +**Important** : La variable fixée dans **host_vars/localhost.yaml** surcharge la variable fixée dans **group_vars/group1.yaml** qui surcharge la variable fixée dans **group_vars/all.yaml**.
 +</WRAP>
 +
 +Exécutez la commande **ansible-playbook** en définissant la valeur de la variable **endroit** sur la ligne de commande :
 +
 +<code>
 +[trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -e 'endroit="la ligne de commande"'
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +
 +TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
 +ok: [web04]
 +ok: [web03]
 +ok: [web02]
 +ok: [web01]
 +ok: [localhost]
 +
 +TASK [debug : debug] *********************************************************************************************************************************************************************************************
 +ok: [localhost] => {
 +    "msg": "Ce message est issu de la ligne de commande"
 } }
 ok: [web01] => { ok: [web01] => {
-    "msg": "Ce message est issu de roles/group_vars/all.yaml"+    "msg": "Ce message est issu de la ligne de commande" 
 +
 +ok: [web02] => { 
 +    "msg": "Ce message est issu de la ligne de commande" 
 +
 +ok: [web03] => { 
 +    "msg": "Ce message est issu de la ligne de commande" 
 +
 +ok: [web04] => { 
 +    "msg": "Ce message est issu de la ligne de commande"
 } }
  
-PLAY RECAP ************************************************************************************************************************************************************** +PLAY RECAP ******************************************************************************************************************************************************************************************************* 
-localhost                  : ok=2    changed=0    unreachable=0    failed=0    +localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web01                      : ok=2    changed=0    unreachable=0    failed=0    +web01                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web02                      : ok=2    changed=0    unreachable=0    failed=0    +web02                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web03                      : ok=2    changed=0    unreachable=0    failed=0    +web03                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    
-web04                      : ok=2    changed=0    unreachable=0    failed=0 +web04                      : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
 </code> </code>
  
-<WRAP center round important 60%+<WRAP center round important> 
-**Important** : La variable fixée dans **host_vars/localhost.yaml** surcharge la variable fixée dans **group_vars/group1.yaml** qui surcharge la variable fixée dans **group_vars/all.yaml**.+**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@centos8 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>
 +**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@centos8 roles]$ vi inventory
 +[trainee@centos8 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@centos8 roles]$ vi playbook.yaml
 +[trainee@centos8 roles]$ cat playbook.yaml
 +---
 +- hosts: all
 +  become: true
 +  roles: 
 +    - exemple01.java 
 +</code>
 +
 +Connectez-vous à la machine TargetA et supprimez le paquet **openjdk-8-jre** :
 +
 +<code>
 +[trainee@centos8 roles]$ ssh 10.0.2.52
 +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 Mar  9 11:29:25 2022 from 10.0.2.45
 +trainee@targeta:~$ sudo apt-get -y remove openjdk-8-jre
 +...
 +trainee@targeta:~$ exit
 +déconnexion
 +Connection to 10.0.2.52 closed.
 +[trainee@centos8 roles]$
 +</code>
 +
 +Utilisez la commande scp pour copier le fichier authorized_keys de la machine virtuelle centos8 vers la machine virtuelle targetb :
 +
 +<code>
 +[trainee@centos8 roles]$ cd ~
 +[trainee@centos8 ~]$ scp .ssh/authorized_keys trainee@10.0.2.53:/home/trainee/.ssh/authorized_keys
 +trainee@10.0.2.53's password: 
 +authorized_keys                                                                                                                                                                 100%  888     8.9KB/  00:00    
 +[trainee@centos8 ~]$ cd -
 +/home/trainee/.ansible/roles
 +[trainee@centos8 roles]$ 
 +</code>
 +
 +Connectez-vous à la machine TargetB et supprimez le paquet **java-1.8.0-openjdk** :
 +
 +<code>
 +[trainee@centos8 roles]$ ssh 10.0.2.53
 +Last login: Wed Mar  9 16:51:41 2022 from 10.0.2.45
 +[trainee@targetb ~]$ sudo yum -y remove java-1.8.0-openjdk
 +...
 +[trainee@targetb ~]$ exit
 +logout
 +Connection to 10.0.2.53 closed.
 +[trainee@centos8 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@centos8 roles]$ vi exemple01.java/tasks/main.yaml
 +[trainee@centos8 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 **centos8** :
 +
 +<code>
 +[trainee@centos8 roles]$ su -
 +Password: fenestros
 +[root@centos8 ~]# vi /etc/hosts
 +[root@centos8 ~]# cat /etc/hosts
 +127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
 +::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 +10.0.2.45 centos8.ittraining.loc centos8
 +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
 +[root@centos8 ~]# exit
 +logout
 +[trainee@centos8 roles]$
 +</code>
 +
 +Connectez-vous en ssh à targeta et testez la configuration de sudo :
 +
 +<code>
 +[trainee@centos8 roles]$ ssh targeta
 +The authenticity of host 'targeta (10.0.2.52)' can't be established.
 +ECDSA key fingerprint is SHA256:sEfHBv9azmK60cjqF/aJgUc9jg56slNaZQdAUcvBOvE.
 +Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
 +Warning: Permanently added 'targeta' (ECDSA) to the list of known hosts.
 +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 Mar  9 16:52:16 2022 from 10.0.2.45
 +
 +trainee@targeta:~$ sudo apt update
 +Réception de:1 http://security.debian.org/debian-security stretch/updates InRelease [53,0 kB]
 +Ign:2 http://ftp.fr.debian.org/debian stretch InRelease               
 +Réception de:3 http://ftp.fr.debian.org/debian stretch-updates InRelease [93,6 kB]
 +Réception de:4 http://ftp.fr.debian.org/debian stretch Release [118 kB]
 +Réception de:5 http://ftp.fr.debian.org/debian stretch Release.gpg [3 177 B]
 +Réception de:6 http://security.debian.org/debian-security stretch/updates/main Sources [396 kB]
 +Réception de:7 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [759 kB]
 +Réception de:8 http://security.debian.org/debian-security stretch/updates/main Translation-en [354 kB]
 +Réception de:9 http://ftp.fr.debian.org/debian stretch/main Sources [6 736 kB]       
 +Réception de:10 http://ftp.fr.debian.org/debian stretch/main amd64 Packages [7 080 kB]
 +Réception de:11 http://ftp.fr.debian.org/debian stretch/main Translation-en [5 377 kB]
 +21,0 Mo réceptionnés en 7s (2 753 ko/s)                                                                                                                                                                          
 +Lecture des listes de paquets... Fait
 +Construction de l'arbre des dépendances       
 +Lecture des informations d'état... Fait
 +333 packages can be upgraded. Run 'apt list --upgradable' to see them.
 +
 +trainee@targeta:~$ exit
 +déconnexion
 +Connection to targeta closed.
 +</code>
 +
 +Connectez-vous en ssh à targetb et testez la configuration de sudo :
 +
 +<code>
 +[trainee@centos8 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' (ECDSA) to the list of known hosts.
 +Last login: Wed Mar  9 16:56:33 2022 from 10.0.2.45
 +
 +[trainee@targetb ~]$ yum clean all
 +Loaded plugins: fastestmirror, langpacks
 +Cleaning repos: base extras updates
 +Other repos take up 190 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
 +
 +[trainee@targetb ~]$ exit
 +logout
 +Connection to targetb closed.
 +[trainee@centos8 roles]$
 +</code>
 +
 +Exécutez **ansible-playbook** et constatez le résultat :
 +
 +<code>
 +[trainee@centos8 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@centos8 roles]$ mkdir vault
 +</code>
 +
 +Éditez le fichier **/home/trainee/.ansible/roles/group_vars/all.yaml** :
 +
 +<code>
 +[trainee@centos8 roles]$ vi /home/trainee/.ansible/roles/group_vars/all.yaml
 +[trainee@centos8 roles]$ cat /home/trainee/.ansible/roles/group_vars/all.yaml
 +---
 +secret: gardezmoisecret
 +</code>
 +
 +Modifiez le fichier **/home/trainee/.ansible/roles/playbook.yaml** :
 +
 +<code>
 +[trainee@centos8 roles]$ vi playbook.yaml
 +[trainee@centos8 roles]$ cat playbook.yaml
 +---
 +- hosts: all
 +  tasks:
 +  - debug:
 +      msg: "Le secret est {{ secret }}"
 +</code>
 +
 +Exécutez la commande **ansible-playbook** :
 +
 +<code>
 +[trainee@centos8 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>
 +**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@centos8 roles]$ ansible-vault encrypt group_vars/all.yaml
 +New Vault password: fenestros
 +Confirm New Vault password: fenestros
 +Encryption successful
 +[trainee@centos8 roles]$ 
 +</code>
 +
 +<WRAP center round important>
 +**Important** : Notez que le mot de passe **fenestros** ne sera pas en clair.
 +</WRAP>
 +
 +<WRAP center round important>
 +**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@centos8 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@centos8 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>
 +**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@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l localhost
 +
 +PLAY [all] *******************************************************************************************************************************************************************************************************
 +ERROR! Attempting to decrypt but no vault secrets found
 +[trainee@centos8 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>
 +**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@centos8 roles]$ ansible-vault edit group_vars/all.yaml
 +Vault password: fenestros
 +</code>
 +
 +<WRAP center round important>
 +**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@centos8 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@centos8 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>
 +**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@centos8 roles]$ ansible-vault decrypt group_vars/all.yaml
 +Vault password: fenestros
 +Decryption successful
 +</code>
 +
 +<WRAP center round important>
 +**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@centos8 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@centos8 roles]$ su -
 +Password: fenestros
 +[root@centos8 ~]#
 +
 +[root@centos8 ~]# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
 +Last metadata expiration check: 1:30:37 ago on Wed 09 Mar 2022 10:10:01 EST.
 +epel-release-latest-8.noarch.rpm                                                                                                                                                   47 kB/s |  22 kB     00:00    
 +Dependencies resolved.
 +==================================================================================================================================================================================================================
 + Package                                              Architecture                                   Version                                           Repository                                            Size
 +==================================================================================================================================================================================================================
 +Installing:
 + epel-release                                         noarch                                         8-14.el8                                          @commandline                                          22 k
 +
 +Transaction Summary
 +==================================================================================================================================================================================================================
 +Install  1 Package
 +
 +Total size: 22 k
 +Installed size: 32 k
 +Is this ok [y/N]: y
 +Downloading Packages:
 +Running transaction check
 +Transaction check succeeded.
 +Running transaction test
 +Transaction test succeeded.
 +Running transaction
 +  Preparing        :                                                                                                                                                                                          1/1 
 +  Installing       : epel-release-8-14.el8.noarch                                                                                                                                                             1/
 +  Running scriptlet: epel-release-8-14.el8.noarch                                                                                                                                                             1/
 +  Verifying        : epel-release-8-14.el8.noarch                                                                                                                                                             1/
 +Installed products updated.
 +
 +Installed:
 +  epel-release-8-14.el8.noarch                                                                                                                                                                                    
 +
 +Complete!
 +
 +[root@centos8 ~]# dnf install pwgen
 +Extra Packages for Enterprise Linux 8 - x86_64                                                                                                                                    1.1 MB/s |  11 MB     00:09    
 +Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                                                                            530 kB/s | 979 kB     00:01    
 +Last metadata expiration check: 0:00:01 ago on Wed 09 Mar 2022 11:41:14 EST.
 +Dependencies resolved.
 +==================================================================================================================================================================================================================
 + Package                                          Architecture                                      Version                                                 Repository                                       Size
 +==================================================================================================================================================================================================================
 +Installing:
 + pwgen                                            x86_64                                            2.08-3.el8                                              epel                                             31 k
 +
 +Transaction Summary
 +==================================================================================================================================================================================================================
 +Install  1 Package
 +
 +Total download size: 31 k
 +Installed size: 46 k
 +Is this ok [y/N]: y
 +
 +[root@centos8 ~]# exit
 +logout
 +[trainee@centos8 roles]$ 
 +</code>
 +
 +Utilisez maintenant la commande **pwgen** pour générer un mot de passe aléatoire :
 +
 +<code>
 +[trainee@centos8 roles]$ pwgen 16 1
 +di3Be1AiPayeehai
 +</code>
 +
 +Utilisez pwgen pour créer un mot de passe aléatoire contenu dans un fichier :
 +
 +<code>
 +[trainee@centos8 roles]$ pwgen 16 1 > vault-password
 +
 +[trainee@centos8 roles]$ ls
 +backend.j2  debug  exemple01.java  geerlingguy.java  group_vars  haproxy  host_vars  inventory  playbook.yaml  tomcat  vault  vault-password
 +
 +[trainee@centos8 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@centos8 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@centos8 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@centos8 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>
 +
  
 ----- -----
-<html> + 
-<div align="center"> +Copyright © 2023 Hugh Norris.
-Copyright © 2019 Hugh NORRIS +
-</div> +
-</html>+
Menu