Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
elearning:workbooks:debian:6:avance:l130:part3 [2021/03/26 10:21] – admin | elearning:workbooks:debian:6:avance:l130:part3 [2023/08/25 01:29] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
~~PDF: | ~~PDF: | ||
- | Version - **2021.01** | + | Version - **2023.01** |
Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
- | ====== | + | ====== |
=====Contenu du Module===== | =====Contenu du Module===== | ||
- | * **DOF503 | + | * **LCF803 |
* Contenu du Module | * Contenu du Module | ||
* LAB #1 - Dépendances de Rôles | * LAB #1 - Dépendances de Rôles | ||
Ligne 25: | Ligne 25: | ||
* 2.6.2 - Le Gabarit Enfant | * 2.6.2 - Le Gabarit Enfant | ||
* LAB #3 - Gestion de la Hiérarchie des Variables | * LAB #3 - Gestion de la Hiérarchie des Variables | ||
+ | * LAB #4 - Utilisation des Facts d' | ||
+ | * 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 #1 - Dépendances de Rôles===== | =====LAB #1 - Dépendances de Rôles===== | ||
Ligne 33: | Ligne 39: | ||
< | < | ||
- | trainee@ansible:~$ mkdir / | + | [trainee@centos8 |
- | trainee@ansible:~$ cd / | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que dans ce Rôle nous n' | **Important** : Notez que dans ce Rôle nous n' | ||
</ | </ | ||
Ligne 46: | Ligne 52: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- name: install jre | - name: install jre | ||
Ligne 61: | Ligne 67: | ||
</ | </ | ||
- | <WRAP center round important | + | <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**, | **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**, | ||
</ | </ | ||
Ligne 68: | Ligne 74: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
java_home: / | java_home: / | ||
Ligne 75: | Ligne 81: | ||
</ | </ | ||
- | <WRAP center round important | + | <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**. | ||
</ | </ | ||
Ligne 82: | Ligne 88: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
</ | </ | ||
- | <WRAP center round important | + | <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. | ||
</ | </ | ||
Ligne 92: | Ligne 98: | ||
< | < | ||
- | trainee@ansible:~$ mkdir / | + | [trainee@centos8 exemple01.java]$ mkdir / |
- | trainee@ansible:~$ cd / | + | [trainee@centos8 exemple01.java]$ cd / |
- | trainee@ansible: | + | [trainee@centos8 |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que dans ce Rôle nous n' | **Important** : Notez que dans ce Rôle nous n' | ||
</ | </ | ||
Ligne 104: | Ligne 110: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- name: install tomcat | - name: install tomcat | ||
Ligne 114: | Ligne 120: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
dependencies: | dependencies: | ||
Ligne 121: | Ligne 127: | ||
</ | </ | ||
- | <WRAP center round important | + | <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**. | ||
</ | </ | ||
Ligne 128: | Ligne 134: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- hosts: all | - hosts: all | ||
Ligne 137: | Ligne 143: | ||
</ | </ | ||
- | <WRAP center round important | + | <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**. | ||
</ | </ | ||
Ligne 151: | Ligne 157: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
. | . | ||
├── exemple01.java | ├── exemple01.java | ||
- | │ ├── defaults | + | │ |
- | │ │ └── main.yaml | + | │ |
- | │ ├── tasks | + | │ |
- | │ │ └── main.yaml | + | │ |
- | │ └── templates | + | │ |
- | │ └── java.sh | + | │ |
├── geerlingguy.java | ├── geerlingguy.java | ||
- | │ ├── defaults | + | │ |
- | │ │ └── main.yml | + | │ |
- | │ ├── LICENSE | + | │ |
- | │ ├── meta | + | │ |
- | │ │ └── main.yml | + | │ |
- | │ ├── molecule | + | │ |
- | │ │ └── default | + | │ |
- | │ │ ├── converge.yml | + | │ |
- | │ │ └── molecule.yml | + | │ |
- | │ ├── README.md | + | │ |
- | │ ├── tasks | + | │ |
- | │ │ ├── main.yml | + | │ |
- | │ │ ├── setup-Debian.yml | + | │ |
- | │ │ ├── setup-FreeBSD.yml | + | │ |
- | │ │ └── setup-RedHat.yml | + | │ |
- | │ ├── templates | + | │ |
- | │ │ └── java_home.sh.j2 | + | │ |
- | │ └── vars | + | │ |
- | │ ├── Debian-10.yml | + | │ |
- | │ ├── Debian-8.yml | + | │ |
- | │ ├── Debian-9.yml | + | │ |
- | │ ├── | + | │ |
- | │ ├── | + | │ |
- | │ ├── | + | │ |
- | │ ├── RedHat-7.yml | + | │ |
- | │ ├── RedHat-8.yml | + | │ |
- | │ ├── Ubuntu-12.yml | + | │ |
- | │ ├── Ubuntu-14.yml | + | │ |
- | │ ├── Ubuntu-16.yml | + | │ |
- | │ ├── Ubuntu-18.yml | + | │ |
- | │ └── Ubuntu-20.yml | + | │ |
├── inventory | ├── inventory | ||
├── playbook.yaml | ├── playbook.yaml | ||
└── tomcat | └── tomcat | ||
├── meta | ├── meta | ||
- | │ └── main.yaml | + | │ |
└── tasks | └── tasks | ||
└── main.yaml | └── main.yaml | ||
+ | |||
15 directories, | 15 directories, | ||
</ | </ | ||
Ligne 205: | Ligne 212: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | 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 | + | web01 : ok=4 changed=2 |
</ | </ | ||
- | <WRAP center round important | + | <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**. | ||
</ | </ | ||
Ligne 234: | Ligne 239: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
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 244: | 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 Mar 24 14:32:15 2021 from 10.0.2.50 | + | Last login: Wed Mar 9 13:49:26 2022 from 10.0.2.45 |
trainee@web01: | trainee@web01: | ||
● tomcat8.service - LSB: Start Tomcat. | ● tomcat8.service - LSB: Start Tomcat. | ||
| | ||
- | | + | |
Docs: man: | Docs: man: | ||
| | ||
- | | + | |
trainee@web01: | trainee@web01: | ||
déconnexion | déconnexion | ||
Connection to web01 closed. | Connection to web01 closed. | ||
- | trainee@ansible: | + | [trainee@centos8 |
</ | </ | ||
Ligne 262: | Ligne 266: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
dependencies: | dependencies: | ||
- | - { role: exemple01.java, | + | - { role: exemple01.java, |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que cette fois-ci, la valeur de la variable **java_package** spécifiée dans le fichier **/ | **Important** : Notez que cette fois-ci, la valeur de la variable **java_package** spécifiée dans le fichier **/ | ||
</ | </ | ||
Ligne 276: | Ligne 280: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | 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 | + | web02 : ok=4 changed=3 |
+ | </ | ||
+ | |||
+ | Vérifiez que la dépendance **tree** a été installée dans Web02 : | ||
+ | |||
+ | < | ||
+ | [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 / | ||
+ | |||
+ | 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: | ||
+ | / | ||
+ | trainee@web02: | ||
+ | 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 / | ||
+ | |||
+ | 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: | ||
+ | trainee@web03: | ||
+ | déconnexion | ||
+ | Connection to web03 closed. | ||
+ | [trainee@centos8 roles]$ | ||
</ | </ | ||
Ligne 304: | Ligne 343: | ||
Les **Gabarits** ou // | Les **Gabarits** ou // | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : La documentation des gabarits se trouvent à cette adresse: **[[https:// | **Important** : La documentation des gabarits se trouvent à cette adresse: **[[https:// | ||
</ | </ | ||
Ligne 313: | Ligne 352: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible:~$ cd / | + | [trainee@centos8 roles]$ cd / |
- | trainee@ansible: | + | [trainee@centos8 |
+ | [trainee@centos8 haproxy]$ | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que dans ce Rôle nous n' | **Important** : Notez que dans ce Rôle nous n' | ||
</ | </ | ||
Ligne 325: | Ligne 365: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- name: install | - name: install | ||
Ligne 344: | Ligne 384: | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que l' | **Important** : Notez que l' | ||
</ | </ | ||
Ligne 351: | Ligne 391: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- name: reload haproxy | - name: reload haproxy | ||
Ligne 361: | Ligne 401: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
global | global | ||
- | log / | + | |
- | log / | + | log / |
- | chroot / | + | chroot / |
- | stats socket / | + | stats socket / |
- | stats timeout 30s | + | stats timeout 30s |
- | user haproxy | + | user haproxy |
- | group haproxy | + | group haproxy |
- | daemon | + | daemon |
- | # Default SSL material locations | + | |
- | ca-base / | + | ca-base / |
- | crt-base / | + | crt-base / |
- | # Default ciphers to use on SSL-enabled listening sockets. | + | |
- | # For more information, | + | # For more information, |
- | # https:// | + | # https:// |
- | # An alternative list with additional directives can be obtained from | + | # An alternative list with additional directives can be obtained from |
- | # https:// | + | # https:// |
- | ssl-default-bind-ciphers ECDH+AESGCM: | + | ssl-default-bind-ciphers ECDH+AESGCM: |
- | ssl-default-bind-options no-sslv3 | + | ssl-default-bind-options no-sslv3 |
defaults | defaults | ||
- | log global | + | |
- | mode http | + | mode http |
- | option httplog | + | option |
- | option dontlognull | + | option |
timeout connect 5000 | timeout connect 5000 | ||
timeout client | timeout client | ||
timeout server | timeout server | ||
- | errorfile 400 / | + | |
- | errorfile 403 / | + | errorfile 403 / |
- | errorfile 408 / | + | errorfile 408 / |
- | errorfile 500 / | + | errorfile 500 / |
- | errorfile 502 / | + | errorfile 502 / |
- | errorfile 503 / | + | errorfile 503 / |
- | errorfile 504 / | + | errorfile 504 / |
frontend haproxy | frontend haproxy | ||
Ligne 414: | Ligne 454: | ||
backend dotcms | backend dotcms | ||
- | server web02 10.0.2.54:8080 check | + | server web02 10.0.2.55:8080 check |
- | server web03 10.0.2.55:8080 check | + | server web03 10.0.2.56:8080 check |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez l' | **Important** : Notez l' | ||
</ | </ | ||
Ligne 425: | Ligne 465: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
haproxy_listen_address: | haproxy_listen_address: | ||
Ligne 436: | Ligne 476: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- hosts: all | - hosts: all | ||
Ligne 449: | Ligne 489: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | 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 | + | web04 : ok=5 changed=2 |
</ | </ | ||
Ligne 477: | Ligne 515: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
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 487: | 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 Mar 24 15:33:40 2021 from 10.0.2.50 | + | Last login: Wed Mar |
trainee@web04: | trainee@web04: | ||
● haproxy.service - HAProxy Load Balancer | ● haproxy.service - HAProxy Load Balancer | ||
| | ||
- | | + | |
Docs: man: | Docs: man: | ||
| | ||
- | Process: | + | Process: |
- | Process: | + | Process: |
- | Main PID: 3166 (haproxy-systemd) | + | Main PID: 5394 (haproxy-systemd) |
Tasks: 3 (limit: 4915) | Tasks: 3 (limit: 4915) | ||
| | ||
- | | + | |
- | | + | |
- | | + | |
trainee@web04: | trainee@web04: | ||
global | global | ||
- | log / | + | |
- | log / | + | log / |
- | chroot / | + | chroot / |
- | stats socket / | + | stats socket / |
- | stats timeout 30s | + | stats timeout 30s |
- | user haproxy | + | user haproxy |
- | group haproxy | + | group haproxy |
- | daemon | + | daemon |
- | # Default SSL material locations | + | |
- | ca-base / | + | ca-base / |
- | crt-base / | + | crt-base / |
- | # Default ciphers to use on SSL-enabled listening sockets. | + | |
- | # For more information, | + | # For more information, |
- | # https:// | + | # https:// |
- | # An alternative list with additional directives can be obtained from | + | # An alternative list with additional directives can be obtained from |
- | # https:// | + | # https:// |
- | ssl-default-bind-ciphers ECDH+AESGCM: | + | ssl-default-bind-ciphers ECDH+AESGCM: |
- | ssl-default-bind-options no-sslv3 | + | ssl-default-bind-options no-sslv3 |
defaults | defaults | ||
- | log global | + | |
- | mode http | + | mode http |
- | option httplog | + | option |
- | option dontlognull | + | option |
timeout connect 5000 | timeout connect 5000 | ||
timeout client | timeout client | ||
timeout server | timeout server | ||
- | errorfile 400 / | + | |
- | errorfile 403 / | + | errorfile 403 / |
- | errorfile 408 / | + | errorfile 408 / |
- | errorfile 500 / | + | errorfile 500 / |
- | errorfile 502 / | + | errorfile 502 / |
- | errorfile 503 / | + | errorfile 503 / |
- | errorfile 504 / | + | errorfile 504 / |
frontend haproxy | frontend haproxy | ||
Ligne 554: | Ligne 594: | ||
backend dotcms | backend dotcms | ||
- | server web02 10.0.2.54:8080 check | + | server web02 10.0.2.55:8080 check |
- | server web03 10.0.2.55:8080 check | + | server web03 10.0.2.56:8080 check |
trainee@web04: | trainee@web04: | ||
déconnexion | déconnexion | ||
Connection to web04 closed. | Connection to web04 closed. | ||
+ | [trainee@centos8 roles]$ | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que les valeurs des variables spécifiées dans le fichier **/ | **Important** : Notez que les valeurs des variables spécifiées dans le fichier **/ | ||
</ | </ | ||
Ligne 573: | Ligne 614: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | |
frontend haproxy | frontend haproxy | ||
bind {{ haproxy_listen_address }}: | bind {{ haproxy_listen_address }}: | ||
Ligne 591: | Ligne 631: | ||
backend dotcms | backend dotcms | ||
- | server web02 10.0.2.54:8080 check | + | server web02 10.0.2.55:8080 check |
- | server web03 10.0.2.55:8080 check | + | server web03 10.0.2.56:8080 check |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez la condition **%%{% if haproxy_stats %}%%** qui ne tiendra compte des quatre lignes jusqu' | **Important** : Notez la condition **%%{% if haproxy_stats %}%%** qui ne tiendra compte des quatre lignes jusqu' | ||
</ | </ | ||
Ligne 602: | Ligne 642: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
haproxy_listen_address: | haproxy_listen_address: | ||
Ligne 611: | Ligne 651: | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez qu' | **Important** : Notez qu' | ||
</ | </ | ||
Ligne 618: | Ligne 658: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | 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 | web04 : ok=4 changed=0 | ||
</ | </ | ||
Ligne 643: | Ligne 681: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
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 653: | 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 Mar 24 15:39:34 2021 from 10.0.2.50 | + | Last login: Wed Mar |
trainee@web04: | trainee@web04: | ||
- | errorfile 504 / | + | |
frontend haproxy | frontend haproxy | ||
Ligne 670: | Ligne 708: | ||
backend dotcms | backend dotcms | ||
- | server web02 10.0.2.54:8080 check | + | server web02 10.0.2.55:8080 check |
- | server web03 10.0.2.55:8080 check | + | server web03 10.0.2.56:8080 check |
trainee@web04: | trainee@web04: | ||
déconnexion | déconnexion | ||
Connection to web04 closed. | Connection to web04 closed. | ||
+ | [trainee@centos8 roles]$ | ||
</ | </ | ||
- | <WRAP center round important | + | <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. | ||
</ | </ | ||
Ligne 685: | Ligne 723: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
haproxy_listen_address: | haproxy_listen_address: | ||
Ligne 694: | Ligne 732: | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez qu' | **Important** : Notez qu' | ||
</ | </ | ||
Ligne 702: | Ligne 740: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | 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 | + | web04 : ok=5 changed=2 |
</ | </ | ||
Ligne 730: | Ligne 766: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
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 740: | 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 Mar 24 15:42:29 2021 from 10.0.2.50 | + | Last login: Wed Mar |
trainee@web04: | trainee@web04: | ||
- | errorfile 408 / | + | |
- | errorfile 500 / | + | errorfile 500 / |
- | errorfile 502 / | + | errorfile 502 / |
- | errorfile 503 / | + | errorfile 503 / |
- | errorfile 504 / | + | errorfile 504 / |
frontend haproxy | frontend haproxy | ||
Ligne 757: | Ligne 793: | ||
backend dotcms | backend dotcms | ||
- | server web02 10.0.2.54:8080 check | + | server web02 10.0.2.55:8080 check |
- | server web03 10.0.2.55:8080 check | + | server web03 10.0.2.56:8080 check |
trainee@web04: | trainee@web04: | ||
déconnexion | déconnexion | ||
Connection to web04 closed. | Connection to web04 closed. | ||
+ | [trainee@centos8 roles]$ | ||
</ | </ | ||
- | <WRAP center round important | + | <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. | ||
</ | </ | ||
Ligne 791: | Ligne 828: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
haproxy_listen_address: | haproxy_listen_address: | ||
Ligne 799: | Ligne 836: | ||
haproxy_stats: | haproxy_stats: | ||
haproxy_backends: | haproxy_backends: | ||
- | - ' | + | - ' |
- | - ' | + | - ' |
</ | </ | ||
- | <WRAP center round important | + | <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. | ||
</ | </ | ||
Ligne 810: | Ligne 847: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
stats auth admin:admin | stats auth admin:admin | ||
{% endif %} | {% endif %} | ||
Ligne 827: | Ligne 864: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
haproxy_listen_address: | haproxy_listen_address: | ||
Ligne 836: | Ligne 873: | ||
haproxy_backends: | haproxy_backends: | ||
web02: | web02: | ||
- | ip: 10.0.2.54 | ||
- | web03: | ||
ip: 10.0.2.55 | ip: 10.0.2.55 | ||
+ | web03: | ||
+ | ip: 10.0.2.56 | ||
</ | </ | ||
Ligne 844: | Ligne 881: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
stats auth admin:admin | stats auth admin:admin | ||
{% endif %} | {% endif %} | ||
Ligne 863: | Ligne 900: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
{% macro backend(name, | {% macro backend(name, | ||
server {{ name }} {{ ip }}:{{ port }} check | server {{ name }} {{ ip }}:{{ port }} check | ||
Ligne 872: | Ligne 909: | ||
Il convient ensuite d' | Il convient ensuite d' | ||
- | <file> | + | <code> |
- | ... | + | [trainee@centos8 roles]$ vi / |
+ | [trainee@centos8 roles]$ tail / | ||
+ | {% endif %} | ||
+ | balance roundrobin | ||
+ | option httpclose | ||
+ | option forwardfor | ||
{% import ' | {% import ' | ||
backend dotcms | backend dotcms | ||
Ligne 879: | Ligne 922: | ||
{{backend.backend(key, | {{backend.backend(key, | ||
{% endfor %} | {% endfor %} | ||
- | </file> | + | </code> |
====2.5 - Filtres==== | ====2.5 - Filtres==== | ||
Ligne 885: | Ligne 928: | ||
===2.5.1 - Default=== | ===2.5.1 - Default=== | ||
- | Le filtre **default** permet de fournir une valeur par défaut pour une variable. Éditez le fichier **/ | + | Le filtre **default** permet de fournir une valeur par défaut pour une variable. Éditez le fichier **/ |
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
bind {{ haproxy_listen_address }}: | bind {{ haproxy_listen_address }}: | ||
mode http | mode http | ||
Ligne 912: | Ligne 955: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
haproxy_listen_address: | haproxy_listen_address: | ||
Ligne 919: | Ligne 962: | ||
haproxy_backends: | haproxy_backends: | ||
web02: | web02: | ||
- | ip: 10.0.2.54 | ||
- | web03: | ||
ip: 10.0.2.55 | ip: 10.0.2.55 | ||
+ | web03: | ||
+ | ip: 10.0.2.56 | ||
</ | </ | ||
Ligne 927: | Ligne 970: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | 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 | + | web04 : ok=5 changed=2 |
</ | </ | ||
Ligne 955: | Ligne 996: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
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 965: | 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 Mar 24 15:55:45 2021 from 10.0.2.50 | + | Last login: Wed Mar |
trainee@web04: | trainee@web04: | ||
- | errorfile 504 / | + | |
frontend haproxy | frontend haproxy | ||
Ligne 982: | Ligne 1023: | ||
backend dotcms | backend dotcms | ||
- | server | + | server |
- | server | + | server |
trainee@web04: | trainee@web04: | ||
déconnexion | déconnexion | ||
Connection to web04 closed. | Connection to web04 closed. | ||
+ | [trainee@centos8 roles]$ | ||
</ | </ | ||
Ligne 1024: | Ligne 1066: | ||
haproxy_backends: | haproxy_backends: | ||
web02: | web02: | ||
- | ip: 10.0.2.54 | ||
- | web03: | ||
ip: 10.0.2.55 | ip: 10.0.2.55 | ||
+ | web03: | ||
+ | ip: 10.0.2.56 | ||
</ | </ | ||
Ligne 1032: | Ligne 1074: | ||
< | < | ||
- | 10.0.2.54,10.0.2.55 | + | 10.0.2.55,10.0.2.56 |
</ | </ | ||
Ligne 1044: | Ligne 1086: | ||
< | < | ||
- | trainee@ansible:~$ vi / | + | [trainee@centos8 roles]$ vi / |
- | trainee@ansible:~$ cat / | + | [trainee@centos8 roles]$ cat / |
global | global | ||
- | log / | + | |
- | log / | + | log / |
- | chroot / | + | chroot / |
- | stats socket / | + | stats socket / |
- | 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 | + | |
- | option dontlognull | + | option |
timeout connect 5000 | timeout connect 5000 | ||
timeout client | timeout client | ||
Ligne 1069: | Ligne 1111: | ||
{% block server %} | {% block server %} | ||
{% endblock %} | {% endblock %} | ||
- | |||
</ | </ | ||
- | <WRAP center round important | + | <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**, | **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**, | ||
</ | </ | ||
Ligne 1081: | Ligne 1122: | ||
< | < | ||
- | trainee@ansible:~$ vi / | + | [trainee@centos8 roles]$ vi / |
- | trainee@ansible:~$ cat / | + | [trainee@centos8 roles]$ cat / |
{% extends ' | {% extends ' | ||
{% block globals %} | {% block globals %} | ||
- | ca-base / | + | |
- | crt-base / | + | crt-base / |
- | ssl-default-bind-ciphers ECDH+AESGCM: | + | ssl-default-bind-ciphers ECDH+AESGCM: |
- | ssl-default-bind-options no-sslv3 | + | ssl-default-bind-options no-sslv3 |
{% endblock %} | {% endblock %} | ||
{% block defaults %} | {% block defaults %} | ||
- | mode http | + | |
- | option httplog | + | option |
- | errorfile 400 / | + | errorfile 400 / |
- | errorfile 403 / | + | errorfile 403 / |
- | errorfile 408 / | + | errorfile 408 / |
- | errorfile 500 / | + | errorfile 500 / |
- | errorfile 502 / | + | errorfile 502 / |
- | errorfile 503 / | + | errorfile 503 / |
- | errorfile 504 / | + | errorfile 504 / |
{% endblock %} | {% endblock %} | ||
{% block server %} | {% block server %} | ||
Ligne 1123: | Ligne 1164: | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que les **blocs** nommés **globals**, | **Important** : Notez que les **blocs** nommés **globals**, | ||
</ | </ | ||
Ligne 1130: | Ligne 1171: | ||
< | < | ||
- | trainee@ansible:~$ vi / | + | [trainee@centos8 roles]$ vi / |
- | trainee@ansible:~$ cat / | + | [trainee@centos8 roles]$ cat / |
--- | --- | ||
- name: install | - name: install | ||
Ligne 1152: | Ligne 1193: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | 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 | + | web04 : ok=5 changed=2 |
</ | </ | ||
Ligne 1180: | Ligne 1219: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
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 1190: | 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 Mar 24 16:00:24 2021 from 10.0.2.50 | + | Last login: Wed Mar 9 15:54:56 2022 from 10.0.2.45 |
trainee@web04: | trainee@web04: | ||
global | global | ||
- | log / | + | |
- | log / | + | log / |
- | chroot / | + | chroot / |
- | stats socket / | + | stats socket / |
- | stats timeout 30s | + | stats timeout 30s |
- | user haproxy | + | user haproxy |
- | group haproxy | + | group haproxy |
- | daemon | + | daemon |
- | ca-base / | + | ca-base / |
- | crt-base / | + | crt-base / |
- | ssl-default-bind-ciphers ECDH+AESGCM: | + | ssl-default-bind-ciphers ECDH+AESGCM: |
- | ssl-default-bind-options no-sslv3 | + | ssl-default-bind-options no-sslv3 |
defaults | defaults | ||
- | log global | + | |
- | option dontlognull | + | option |
timeout connect 5000 | timeout connect 5000 | ||
timeout client | timeout client | ||
timeout server | timeout server | ||
- | mode http | + | |
- | option httplog | + | option |
- | errorfile 400 / | + | errorfile 400 / |
- | errorfile 403 / | + | errorfile 403 / |
- | errorfile 408 / | + | errorfile 408 / |
- | errorfile 500 / | + | errorfile 500 / |
- | errorfile 502 / | + | errorfile 502 / |
- | errorfile 503 / | + | errorfile 503 / |
- | errorfile 504 / | + | errorfile 504 / |
frontend haproxy | frontend haproxy | ||
Ligne 1235: | Ligne 1274: | ||
backend dotcms | backend dotcms | ||
- | server web02 10.0.2.54:8080 check | + | server web02 10.0.2.55:8080 check |
- | server web03 10.0.2.55:8080 check | + | server web03 10.0.2.56:8080 check |
trainee@web04: | trainee@web04: | ||
déconnexion | déconnexion | ||
Connection to web04 closed. | Connection to web04 closed. | ||
+ | [trainee@centos8 roles]$ | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que les **blocs** nommés **globals**, | **Important** : Notez que les **blocs** nommés **globals**, | ||
</ | </ | ||
Ligne 1249: | Ligne 1288: | ||
=====LAB #3 - Gestion de la Hiérarchie des Variables===== | =====LAB #3 - Gestion de la Hiérarchie des Variables===== | ||
- | La hiérarchie de la prise en compte des variables par Ansible peut être illustrée par le diagremme suvant | + | La hiérarchie de la prise en compte des variables par Ansible peut être illustrée par le diagramme suivant |
- | {{ : | + | < |
+ | . | ||
+ | ├── 1.commandline | ||
+ | └── roles | ||
+ | ├── 4.playbook.yaml | ||
+ | ├── debug | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | ├── group_vars | ||
+ | │ | ||
+ | │ | ||
+ | └── host_vars | ||
+ | └── 2.hostname.yaml | ||
+ | </ | ||
- | Créez | + | Pour illustrer cette hiérarchie, |
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible:~$ mkdir / | + | [trainee@centos8 |
- | trainee@ansible:~$ mkdir / | + | [trainee@centos8 |
- | trainee@ansible:~$ mkdir / | + | [trainee@centos8 |
+ | [trainee@centos8 ~]$ | ||
</ | </ | ||
Ligne 1265: | Ligne 1320: | ||
< | < | ||
- | trainee@ansible:~$ touch / | + | [trainee@centos8 |
- | trainee@ansible:~$ touch / | + | [trainee@centos8 |
+ | [trainee@centos8 ~]$ | ||
</ | </ | ||
Ligne 1272: | Ligne 1328: | ||
< | < | ||
- | trainee@ansible:~$ cd .ansible/ | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
debug | debug | ||
├── defaults | ├── defaults | ||
- | │ └── main.yaml | + | │ |
└── tasks | └── tasks | ||
└── main.yaml | └── main.yaml | ||
Ligne 1286: | Ligne 1342: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
+ | [trainee@centos8 roles]$ | ||
</ | </ | ||
Ligne 1293: | Ligne 1350: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
group_vars/ | group_vars/ | ||
└── all.yaml | └── all.yaml | ||
Ligne 1303: | Ligne 1360: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- debug: | - debug: | ||
Ligne 1313: | Ligne 1370: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- hosts: all | - hosts: all | ||
Ligne 1324: | Ligne 1381: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | PLAY [all] ********************************************************************************************************************************************* | + | PLAY [all] ******************************************************************************************************************************************************************************************************* |
- | TASK [Gathering Facts] ********************************************************************************************************************************* | + | TASK [Gathering Facts] |
ok: [web04] | ok: [web04] | ||
- | ok: [web01] | ||
ok: [web03] | ok: [web03] | ||
ok: [web02] | ok: [web02] | ||
+ | ok: [web01] | ||
- | TASK [debug : debug] *********************************************************************************************************************************** | + | TASK [debug : debug] |
ok: [web01] => { | ok: [web01] => { | ||
" | " | ||
Ligne 1350: | Ligne 1405: | ||
} | } | ||
- | PLAY RECAP ********************************************************************************************************************************************* | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
web01 : ok=2 changed=0 | web01 : ok=2 changed=0 | ||
web02 : ok=2 changed=0 | web02 : ok=2 changed=0 | ||
web03 : ok=2 changed=0 | web03 : ok=2 changed=0 | ||
- | web04 : ok=2 changed=0 | + | web04 : ok=2 changed=0 |
</ | </ | ||
Ligne 1360: | Ligne 1415: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
endroit: ' | endroit: ' | ||
Ligne 1369: | Ligne 1424: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | PLAY [all] ********************************************************************************************************************************************* | + | PLAY [all] ******************************************************************************************************************************************************************************************************* |
- | TASK [Gathering Facts] ********************************************************************************************************************************* | + | TASK [Gathering Facts] ******************************************************************************************************************************************************************************************* |
- | ok: [web01] | + | |
ok: [web03] | ok: [web03] | ||
- | ok: [web02] | ||
ok: [web04] | ok: [web04] | ||
+ | ok: [web02] | ||
+ | ok: [web01] | ||
- | TASK [debug : debug] *********************************************************************************************************************************** | + | TASK [debug : debug] |
ok: [web01] => { | ok: [web01] => { | ||
" | " | ||
Ligne 1395: | Ligne 1448: | ||
} | } | ||
- | PLAY RECAP ********************************************************************************************************************************************* | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
web01 : ok=2 changed=0 | web01 : ok=2 changed=0 | ||
web02 : ok=2 changed=0 | web02 : ok=2 changed=0 | ||
Ligne 1402: | Ligne 1455: | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : La variable fixée dans **defaults/ | **Important** : La variable fixée dans **defaults/ | ||
</ | </ | ||
Ligne 1409: | Ligne 1462: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
endroit: ' | endroit: ' | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : La déclaration de la variable peut être faite dans **roles/ | **Important** : La déclaration de la variable peut être faite dans **roles/ | ||
</ | </ | ||
Ligne 1422: | Ligne 1475: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | PLAY [all] ********************************************************************************************************************************************* | + | PLAY [all] ******************************************************************************************************************************************************************************************************* |
- | TASK [Gathering Facts] ********************************************************************************************************************************* | + | TASK [Gathering Facts] ******************************************************************************************************************************************************************************************* |
- | ok: [web01] | + | |
- | ok: [web02] | + | |
ok: [web04] | ok: [web04] | ||
ok: [web03] | ok: [web03] | ||
+ | ok: [web01] | ||
+ | ok: [web02] | ||
- | TASK [debug : debug] *********************************************************************************************************************************** | + | TASK [debug : debug] |
ok: [web01] => { | ok: [web01] => { | ||
" | " | ||
Ligne 1448: | Ligne 1499: | ||
} | } | ||
- | PLAY RECAP ********************************************************************************************************************************************* | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
web01 : ok=2 changed=0 | web01 : ok=2 changed=0 | ||
web02 : ok=2 changed=0 | web02 : ok=2 changed=0 | ||
web03 : ok=2 changed=0 | web03 : ok=2 changed=0 | ||
- | web04 : ok=2 changed=0 | + | web04 : ok=2 changed=0 |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : La variable fixée dans **group_vars/ | **Important** : La variable fixée dans **group_vars/ | ||
</ | </ | ||
Ligne 1462: | Ligne 1513: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
--- | --- | ||
- hosts: all | - hosts: all | ||
Ligne 1473: | Ligne 1524: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | PLAY [all] ********************************************************************************************************************************************* | + | PLAY [all] ******************************************************************************************************************************************************************************************************* |
- | TASK [Gathering Facts] ********************************************************************************************************************************* | + | TASK [Gathering Facts] |
ok: [web02] | ok: [web02] | ||
- | ok: [web01] | ||
ok: [web03] | ok: [web03] | ||
+ | ok: [web01] | ||
ok: [web04] | ok: [web04] | ||
- | TASK [debug : debug] *********************************************************************************************************************************** | + | TASK [debug : debug] |
ok: [web01] => { | ok: [web01] => { | ||
" | " | ||
Ligne 1499: | Ligne 1548: | ||
} | } | ||
- | PLAY RECAP ********************************************************************************************************************************************* | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
web01 : ok=2 changed=0 | web01 : ok=2 changed=0 | ||
web02 : ok=2 changed=0 | web02 : ok=2 changed=0 | ||
Ligne 1506: | Ligne 1555: | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : La variable fixée dans **playbook.yaml** surcharge la variable fixée dans **group_vars/ | **Important** : La variable fixée dans **playbook.yaml** surcharge la variable fixée dans **group_vars/ | ||
- | </ | ||
- | |||
- | Exécutez la commande **ansible-playbook** en définissant la valeur de la variable **endroit** sur la ligne de commande : | ||
- | |||
- | < | ||
- | trainee@ansible: | ||
- | / | ||
- | from cryptography.exceptions import InvalidSignature | ||
- | |||
- | PLAY [all] ********************************************************************************************************************************************* | ||
- | |||
- | TASK [Gathering Facts] ********************************************************************************************************************************* | ||
- | ok: [web03] | ||
- | ok: [web02] | ||
- | ok: [web04] | ||
- | ok: [web01] | ||
- | |||
- | TASK [debug : debug] *********************************************************************************************************************************** | ||
- | ok: [web01] => { | ||
- | " | ||
- | } | ||
- | ok: [web02] => { | ||
- | " | ||
- | } | ||
- | ok: [web03] => { | ||
- | " | ||
- | } | ||
- | ok: [web04] => { | ||
- | " | ||
- | } | ||
- | |||
- | PLAY RECAP ********************************************************************************************************************************************* | ||
- | web01 : ok=2 changed=0 | ||
- | web02 : ok=2 changed=0 | ||
- | web03 : ok=2 changed=0 | ||
- | web04 : ok=2 changed=0 | ||
- | </ | ||
- | |||
- | <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/ | ||
</ | </ | ||
Ligne 1553: | Ligne 1562: | ||
< | < | ||
- | trainee@ansible:~$ vi / | + | [trainee@centos8 roles]$ vi / |
- | trainee@ansible:~$ cat / | + | [trainee@centos8 roles]$ cat / |
--- | --- | ||
endroit: ' | endroit: ' | ||
Ligne 1562: | Ligne 1571: | ||
< | < | ||
- | trainee@ansible:~$ mkdir / | + | [trainee@centos8 roles]$ mkdir / |
- | trainee@ansible:~$ vi / | + | [trainee@centos8 roles]$ vi / |
- | trainee@ansible:~$ cat / | + | [trainee@centos8 roles]$ cat / |
--- | --- | ||
# endroit: ' | # endroit: ' | ||
Ligne 1572: | Ligne 1581: | ||
< | < | ||
- | trainee@ansible:~$ vi / | + | [trainee@centos8 roles]$ vi / |
- | trainee@ansible:~$ cat / | + | [trainee@centos8 roles]$ cat / |
--- | --- | ||
- hosts: all | - hosts: all | ||
Ligne 1583: | Ligne 1592: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
localhost ansible_connection=local | localhost ansible_connection=local | ||
Ligne 1609: | Ligne 1618: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | PLAY [all] ********************************************************************************************************************************************* | + | PLAY [all] ******************************************************************************************************************************************************************************************************* |
- | TASK [Gathering Facts] ********************************************************************************************************************************* | + | TASK [Gathering Facts] ******************************************************************************************************************************************************************************************* |
+ | ok: [web04] | ||
ok: [web01] | ok: [web01] | ||
ok: [web02] | ok: [web02] | ||
ok: [web03] | ok: [web03] | ||
- | ok: [web04] | ||
ok: [localhost] | ok: [localhost] | ||
- | TASK [debug : debug] *********************************************************************************************************************************** | + | TASK [debug : debug] |
ok: [localhost] => { | ok: [localhost] => { | ||
" | " | ||
Ligne 1639: | Ligne 1646: | ||
} | } | ||
- | PLAY RECAP ********************************************************************************************************************************************* | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
localhost | localhost | ||
web01 : ok=2 changed=0 | web01 : ok=2 changed=0 | ||
web02 : ok=2 changed=0 | web02 : ok=2 changed=0 | ||
web03 : ok=2 changed=0 | web03 : ok=2 changed=0 | ||
- | web04 : ok=2 changed=0 | + | web04 : ok=2 changed=0 |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que la valeur de la variable **endroit** spécifiée dans le fichier **group_vars/ | **Important** : Notez que la valeur de la variable **endroit** spécifiée dans le fichier **group_vars/ | ||
</ | </ | ||
Ligne 1654: | Ligne 1661: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | trainee@ansible: | + | [trainee@centos8 |
[group1] | [group1] | ||
localhost ansible_connection=local | localhost ansible_connection=local | ||
Ligne 1681: | Ligne 1688: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | PLAY [all] ********************************************************************************************************************************************* | + | PLAY [all] ******************************************************************************************************************************************************************************************************* |
- | TASK [Gathering Facts] ********************************************************************************************************************************* | + | TASK [Gathering Facts] |
ok: [web03] | ok: [web03] | ||
ok: [web01] | ok: [web01] | ||
Ligne 1694: | Ligne 1699: | ||
ok: [localhost] | ok: [localhost] | ||
- | TASK [debug : debug] *********************************************************************************************************************************** | + | TASK [debug : debug] |
ok: [localhost] => { | ok: [localhost] => { | ||
" | " | ||
Ligne 1711: | Ligne 1716: | ||
} | } | ||
- | PLAY RECAP ********************************************************************************************************************************************* | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
localhost | localhost | ||
web01 : ok=2 changed=0 | web01 : ok=2 changed=0 | ||
Ligne 1719: | Ligne 1724: | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : La variable fixée dans **group_vars/ | **Important** : La variable fixée dans **group_vars/ | ||
</ | </ | ||
Ligne 1726: | Ligne 1731: | ||
< | < | ||
- | trainee@ansible:~$ vi / | + | [trainee@centos8 roles]$ vi / |
- | trainee@ansible:~$ cat / | + | [trainee@centos8 roles]$ cat / |
--- | --- | ||
endroit: ' | endroit: ' | ||
Ligne 1735: | Ligne 1740: | ||
< | < | ||
- | trainee@ansible: | + | [trainee@centos8 |
- | / | + | |
- | from cryptography.exceptions import InvalidSignature | + | |
- | PLAY [all] ********************************************************************************************************************************************* | + | PLAY [all] ******************************************************************************************************************************************************************************************************* |
- | TASK [Gathering Facts] ********************************************************************************************************************************* | + | TASK [Gathering Facts] |
- | ok: [localhost] | + | ok: [web02] |
ok: [web03] | ok: [web03] | ||
ok: [web01] | ok: [web01] | ||
ok: [web04] | ok: [web04] | ||
- | ok: [web02] | + | ok: [localhost] |
- | TASK [debug : debug] *********************************************************************************************************************************** | + | TASK [debug : debug] |
ok: [localhost] => { | ok: [localhost] => { | ||
" | " | ||
Ligne 1765: | Ligne 1768: | ||
} | } | ||
- | PLAY RECAP ********************************************************************************************************************************************* | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
localhost | localhost | ||
web01 : ok=2 changed=0 | web01 : ok=2 changed=0 | ||
web02 : ok=2 changed=0 | web02 : ok=2 changed=0 | ||
web03 : ok=2 changed=0 | web03 : ok=2 changed=0 | ||
- | web04 : ok=2 changed=0 | + | web04 : ok=2 changed=0 |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : La variable fixée dans **host_vars/ | **Important** : La variable fixée dans **host_vars/ | ||
</ | </ | ||
+ | |||
+ | Exécutez la commande **ansible-playbook** en définissant la valeur de la variable **endroit** sur la ligne de commande : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -e ' | ||
+ | |||
+ | PLAY [all] ******************************************************************************************************************************************************************************************************* | ||
+ | |||
+ | TASK [Gathering Facts] ******************************************************************************************************************************************************************************************* | ||
+ | ok: [web04] | ||
+ | ok: [web03] | ||
+ | ok: [web02] | ||
+ | ok: [web01] | ||
+ | ok: [localhost] | ||
+ | |||
+ | TASK [debug : debug] ********************************************************************************************************************************************************************************************* | ||
+ | ok: [localhost] => { | ||
+ | " | ||
+ | } | ||
+ | ok: [web01] => { | ||
+ | " | ||
+ | } | ||
+ | ok: [web02] => { | ||
+ | " | ||
+ | } | ||
+ | ok: [web03] => { | ||
+ | " | ||
+ | } | ||
+ | ok: [web04] => { | ||
+ | " | ||
+ | } | ||
+ | |||
+ | PLAY RECAP ******************************************************************************************************************************************************************************************************* | ||
+ | localhost | ||
+ | web01 : ok=2 changed=0 | ||
+ | web02 : ok=2 changed=0 | ||
+ | web03 : ok=2 changed=0 | ||
+ | web04 : ok=2 changed=0 | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : La variable fixée dans sur la **ligne de commande** surcharge toutes les autres variables. | ||
+ | </ | ||
+ | |||
+ | =====LAB #4 - Utilisation des Facts d' | ||
+ | |||
+ | Ansible Facts sont : | ||
+ | |||
+ | * des variables collectées automatiquement par le module **setup** d' | ||
+ | * spécifiques à l' | ||
+ | |||
+ | Il est cependant possible d' | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ansible all -i web01, -m setup | more | ||
+ | web01 | SUCCESS => { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | --More-- | ||
+ | </ | ||
+ | |||
+ | <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 ! | ||
+ | </ | ||
+ | |||
+ | Parmi les Facts, les plus utiles sont : | ||
+ | |||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | |||
+ | Ainsi que dictionnaire **ansible_default_ipv4** : | ||
+ | |||
+ | < | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | </ | ||
+ | |||
+ | Modifiez le fichier **inventory** en mettant les deux machines TargetA et TargetB dans le groupe **linux** : | ||
+ | |||
+ | < | ||
+ | [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: | ||
+ | basededonnees | ||
+ | dotcms | ||
+ | equilibrage | ||
+ | |||
+ | [debian: | ||
+ | ansible_user=trainee | ||
+ | </ | ||
+ | |||
+ | Modifiez le fichier **playbook.yaml** afin d' | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ vi playbook.yaml | ||
+ | [trainee@centos8 roles]$ cat playbook.yaml | ||
+ | --- | ||
+ | - hosts: all | ||
+ | become: true | ||
+ | roles: | ||
+ | - exemple01.java | ||
+ | </ | ||
+ | |||
+ | Connectez-vous à la machine TargetA et supprimez le paquet **openjdk-8-jre** : | ||
+ | |||
+ | < | ||
+ | [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 / | ||
+ | |||
+ | 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: | ||
+ | ... | ||
+ | trainee@targeta: | ||
+ | déconnexion | ||
+ | Connection to 10.0.2.52 closed. | ||
+ | [trainee@centos8 roles]$ | ||
+ | </ | ||
+ | |||
+ | Utilisez la commande scp pour copier le fichier authorized_keys de la machine virtuelle centos8 vers la machine virtuelle targetb : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ cd ~ | ||
+ | [trainee@centos8 ~]$ scp .ssh/ | ||
+ | trainee@10.0.2.53' | ||
+ | authorized_keys | ||
+ | [trainee@centos8 ~]$ cd - | ||
+ | / | ||
+ | [trainee@centos8 roles]$ | ||
+ | </ | ||
+ | |||
+ | Connectez-vous à la machine TargetB et supprimez le paquet **java-1.8.0-openjdk** : | ||
+ | |||
+ | < | ||
+ | [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]$ | ||
+ | </ | ||
+ | |||
+ | Grâce au Fact **ansible_os_family** il est possible d' | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ vi exemple01.java/ | ||
+ | [trainee@centos8 roles]$ cat exemple01.java/ | ||
+ | --- | ||
+ | - name: install jre (Debian) | ||
+ | package: name=openjdk-8-jre state=present | ||
+ | when: ansible_os_family == ' | ||
+ | |||
+ | - name: install jre (CentOS) | ||
+ | package: name=java-1.8.0-openjdk state=present | ||
+ | when: ansible_os_family == ' | ||
+ | </ | ||
+ | |||
+ | Modifiez le fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ su - | ||
+ | Password: fenestros | ||
+ | [root@centos8 ~]# vi /etc/hosts | ||
+ | [root@centos8 ~]# cat /etc/hosts | ||
+ | 127.0.0.1 | ||
+ | ::1 | ||
+ | 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]$ | ||
+ | </ | ||
+ | |||
+ | Connectez-vous en ssh à targeta et testez la configuration de sudo : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ssh targeta | ||
+ | The authenticity of host ' | ||
+ | ECDSA key fingerprint is SHA256: | ||
+ | Are you sure you want to continue connecting (yes/ | ||
+ | Warning: Permanently added ' | ||
+ | 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 / | ||
+ | |||
+ | 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: | ||
+ | Réception de:1 http:// | ||
+ | Ign:2 http:// | ||
+ | Réception de:3 http:// | ||
+ | Réception de:4 http:// | ||
+ | Réception de:5 http:// | ||
+ | Réception de:6 http:// | ||
+ | Réception de:7 http:// | ||
+ | Réception de:8 http:// | ||
+ | Réception de:9 http:// | ||
+ | Réception de:10 http:// | ||
+ | Réception de:11 http:// | ||
+ | 21,0 Mo réceptionnés en 7s (2 753 ko/s) | ||
+ | Lecture des listes de paquets... Fait | ||
+ | Construction de l' | ||
+ | Lecture des informations d' | ||
+ | 333 packages can be upgraded. Run 'apt list --upgradable' | ||
+ | |||
+ | trainee@targeta: | ||
+ | déconnexion | ||
+ | Connection to targeta closed. | ||
+ | </ | ||
+ | |||
+ | Connectez-vous en ssh à targetb et testez la configuration de sudo : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ssh targetb | ||
+ | The authenticity of host ' | ||
+ | ECDSA key fingerprint is SHA256: | ||
+ | Are you sure you want to continue connecting (yes/ | ||
+ | Warning: Permanently added ' | ||
+ | Last login: Wed Mar 9 16:56:33 2022 from 10.0.2.45 | ||
+ | |||
+ | [trainee@targetb ~]$ yum clean all | ||
+ | Loaded plugins: fastestmirror, | ||
+ | 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, | ||
+ | Loading mirror speeds from cached hostfile | ||
+ | * base: centos.mirror.ate.info | ||
+ | * extras: mirror.plusserver.com | ||
+ | * updates: mirror.plusserver.com | ||
+ | base | 3.6 kB 00: | ||
+ | extras | ||
+ | updates | ||
+ | (1/6): extras/ | ||
+ | (2/6): base/ | ||
+ | (3/6): base/ | ||
+ | (4/6): extras/ | ||
+ | (5/6): updates/ | ||
+ | (6/6): updates/ | ||
+ | Metadata Cache Created | ||
+ | |||
+ | [trainee@targetb ~]$ exit | ||
+ | logout | ||
+ | Connection to targetb closed. | ||
+ | [trainee@centos8 roles]$ | ||
+ | </ | ||
+ | |||
+ | Exécutez **ansible-playbook** et constatez le résultat : | ||
+ | |||
+ | < | ||
+ | [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 | ||
+ | targetb | ||
+ | </ | ||
+ | |||
+ | Les conditions peuvent être combinées grâce à **and** et **or**. En voici un exemple : | ||
+ | |||
+ | < | ||
+ | tasks: | ||
+ | - name: " | ||
+ | command: / | ||
+ | when: (ansible_distribution == " | ||
+ | (ansible_distribution == " | ||
+ | </ | ||
+ | |||
+ | =====LAB #5 - La Commande ansible-vault===== | ||
+ | |||
+ | La commande **ansible-vault** permet de créer et d' | ||
+ | |||
+ | Pour illustrer son utilisation, | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ mkdir vault | ||
+ | </ | ||
+ | |||
+ | Éditez le fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ vi / | ||
+ | [trainee@centos8 roles]$ cat / | ||
+ | --- | ||
+ | secret: gardezmoisecret | ||
+ | </ | ||
+ | |||
+ | Modifiez le fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ vi playbook.yaml | ||
+ | [trainee@centos8 roles]$ cat playbook.yaml | ||
+ | --- | ||
+ | - hosts: all | ||
+ | tasks: | ||
+ | - debug: | ||
+ | msg: "Le secret est {{ secret }}" | ||
+ | </ | ||
+ | |||
+ | Exécutez la commande **ansible-playbook** : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l localhost | ||
+ | |||
+ | PLAY [all] ******************************************************************************************************************************************************************************************************* | ||
+ | |||
+ | TASK [Gathering Facts] ******************************************************************************************************************************************************************************************* | ||
+ | ok: [localhost] | ||
+ | |||
+ | TASK [debug] ***************************************************************************************************************************************************************************************************** | ||
+ | ok: [localhost] => { | ||
+ | " | ||
+ | } | ||
+ | |||
+ | PLAY RECAP ******************************************************************************************************************************************************************************************************* | ||
+ | localhost | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : L' | ||
+ | </ | ||
+ | |||
+ | ====5.1 - Crypter le Fichier==== | ||
+ | |||
+ | Cryptez maintenant le fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ansible-vault encrypt group_vars/ | ||
+ | New Vault password: fenestros | ||
+ | Confirm New Vault password: fenestros | ||
+ | Encryption successful | ||
+ | [trainee@centos8 roles]$ | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : Notez que le mot de passe **fenestros** ne sera pas en clair. | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : Notez que le mot de passe est pour la commande **ansible-vault** et non pas uniquement pour l' | ||
+ | </ | ||
+ | |||
+ | Constatez maintenant le contenu du fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ cat / | ||
+ | $ANSIBLE_VAULT; | ||
+ | 33343664333931323331346338346439613439633633396262393733663463363438663163383761 | ||
+ | 6566653230323032396434356132653262313962633265630a366436666261363933343663623131 | ||
+ | 63373230663530313864373236316465333464323131643933363664303332336261353732623064 | ||
+ | 3538303864633035320a376235333637656534376638613661303765373165383936653336646562 | ||
+ | 31376535333861616165346433306230366231333139323062366432333033386366 | ||
+ | </ | ||
+ | |||
+ | Exécutez de nouveau la commande **ansible-playbook** : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ansible-playbook -i inventory playbook.yaml -l localhost | ||
+ | |||
+ | PLAY [all] ******************************************************************************************************************************************************************************************************* | ||
+ | ERROR! Attempting to decrypt but no vault secrets found | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : Notez l' | ||
+ | </ | ||
+ | |||
+ | Pour indiquer à la commande **ansible-playbook** que le fichier qui doit être lu soit crypté, utilisez l' | ||
+ | |||
+ | < | ||
+ | [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] => { | ||
+ | " | ||
+ | } | ||
+ | |||
+ | PLAY RECAP ******************************************************************************************************************************************************************************************************* | ||
+ | localhost | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : Notez que le mot de passe **fenestros** ne sera pas en clair. | ||
+ | </ | ||
+ | |||
+ | ====5.2 - Editer le Fichier==== | ||
+ | |||
+ | Pour éditer le fichier, utilisez la sous-commande **edit** de la commande **ansible-vault** : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ansible-vault edit group_vars/ | ||
+ | Vault password: fenestros | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : Notez que le mot de passe **fenestros** ne sera pas en clair. | ||
+ | </ | ||
+ | |||
+ | Le fichier est chargé en mémoire pour édition : | ||
+ | |||
+ | < | ||
+ | --- | ||
+ | secret: gardezlesecret | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | -- INSERT -- | ||
+ | </ | ||
+ | |||
+ | Modifiez le secret et sauvegardez le fichier : | ||
+ | |||
+ | < | ||
+ | --- | ||
+ | secret: gardezlesecret | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | ~ | ||
+ | :x | ||
+ | </ | ||
+ | |||
+ | Constatez que le contenu du fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ cat / | ||
+ | $ANSIBLE_VAULT; | ||
+ | 36633861376466313363373336643832646663666334633931663262666361306236386232316461 | ||
+ | 3331633863386666626230663038653136653830303465660a353337316634363465663962336365 | ||
+ | 61396430313965653666333738376663336139613566636437353935653232306264336235333538 | ||
+ | 6439366539653436310a666361313237623137666634663439343132393532623962353163303364 | ||
+ | 37626635363832333934363930383265313932663230356234343235643935353535 | ||
+ | </ | ||
+ | |||
+ | Exécutez de nouveau la commande **ansible-playbook** avec l' | ||
+ | |||
+ | < | ||
+ | [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] => { | ||
+ | " | ||
+ | } | ||
+ | |||
+ | PLAY RECAP ******************************************************************************************************************************************************************************************************* | ||
+ | localhost | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : Notez que le mot de passe **fenestros** ne sera pas en clair. | ||
+ | </ | ||
+ | |||
+ | ====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** : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ansible-vault decrypt group_vars/ | ||
+ | Vault password: fenestros | ||
+ | Decryption successful | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important> | ||
+ | **Important** : Notez que le mot de passe **fenestros** ne sera pas en clair. | ||
+ | </ | ||
+ | |||
+ | Constatez que le contenu du fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ cat / | ||
+ | --- | ||
+ | secret: gardezlesecret | ||
+ | </ | ||
+ | |||
+ | ====5.4 - Utilisation de Mots de Passe Aléatoires==== | ||
+ | |||
+ | Installez le paquet **pwgen** : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ su - | ||
+ | Password: fenestros | ||
+ | [root@centos8 ~]# | ||
+ | |||
+ | [root@centos8 ~]# dnf install https:// | ||
+ | Last metadata expiration check: 1:30:37 ago on Wed 09 Mar 2022 10:10:01 EST. | ||
+ | epel-release-latest-8.noarch.rpm | ||
+ | Dependencies resolved. | ||
+ | ================================================================================================================================================================================================================== | ||
+ | | ||
+ | ================================================================================================================================================================================================================== | ||
+ | Installing: | ||
+ | | ||
+ | |||
+ | Transaction Summary | ||
+ | ================================================================================================================================================================================================================== | ||
+ | Install | ||
+ | |||
+ | 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 | ||
+ | Installing | ||
+ | Running scriptlet: epel-release-8-14.el8.noarch | ||
+ | Verifying | ||
+ | Installed products updated. | ||
+ | |||
+ | Installed: | ||
+ | epel-release-8-14.el8.noarch | ||
+ | |||
+ | Complete! | ||
+ | |||
+ | [root@centos8 ~]# dnf install pwgen | ||
+ | Extra Packages for Enterprise Linux 8 - x86_64 | ||
+ | Extra Packages for Enterprise Linux Modular 8 - x86_64 | ||
+ | Last metadata expiration check: 0:00:01 ago on Wed 09 Mar 2022 11:41:14 EST. | ||
+ | Dependencies resolved. | ||
+ | ================================================================================================================================================================================================================== | ||
+ | | ||
+ | ================================================================================================================================================================================================================== | ||
+ | Installing: | ||
+ | | ||
+ | |||
+ | Transaction Summary | ||
+ | ================================================================================================================================================================================================================== | ||
+ | Install | ||
+ | |||
+ | Total download size: 31 k | ||
+ | Installed size: 46 k | ||
+ | Is this ok [y/N]: y | ||
+ | |||
+ | [root@centos8 ~]# exit | ||
+ | logout | ||
+ | [trainee@centos8 roles]$ | ||
+ | </ | ||
+ | |||
+ | Utilisez maintenant la commande **pwgen** pour générer un mot de passe aléatoire : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ pwgen 16 1 | ||
+ | di3Be1AiPayeehai | ||
+ | </ | ||
+ | |||
+ | Utilisez pwgen pour créer un mot de passe aléatoire contenu dans un fichier : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ pwgen 16 1 > vault-password | ||
+ | |||
+ | [trainee@centos8 roles]$ ls | ||
+ | backend.j2 | ||
+ | |||
+ | [trainee@centos8 roles]$ cat vault-password | ||
+ | oo3aeph5PaiVeiBu | ||
+ | </ | ||
+ | |||
+ | Utilisez maintenant le mot de passe aléatoire contenu dans le fichier **vault-password** pour crypter le fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ ansible-vault encrypt group_vars/ | ||
+ | Encryption successful | ||
+ | </ | ||
+ | |||
+ | Constatez le contenu du fichier **/ | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 roles]$ cat group_vars/ | ||
+ | $ANSIBLE_VAULT; | ||
+ | 61326364653334653935643735623863353362333536396638356362376631633732306332316661 | ||
+ | 6662333436336237346433363637393666623165643438620a343436366136386637343238303063 | ||
+ | 38383866386631363834623461323334313030623136333334646335626165363263373966373663 | ||
+ | 3137333330653635620a396133346264656335633530353966383930613731626639393631623066 | ||
+ | 31323331383563373830306331653166326563333135326631363461313666313864 | ||
+ | </ | ||
+ | |||
+ | Exécutez de nouveau la commande **ansible-playbook** avec l' | ||
+ | |||
+ | < | ||
+ | [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] => { | ||
+ | " | ||
+ | } | ||
+ | |||
+ | PLAY RECAP ******************************************************************************************************************************************************************************************************* | ||
+ | localhost | ||
+ | </ | ||
+ | |||
----- | ----- | ||
- | < | + | |
- | <div align=" | + | Copyright © 2023 Hugh Norris. |
- | Copyright © 2021 Hugh NORRIS | + | |
- | </ | + | |
- | </ | + |