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:part2 [2020/04/12 12:59] – admin | elearning:workbooks:debian:6:avance:l130:part2 [2023/08/25 01:28] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
~~PDF: | ~~PDF: | ||
- | Version : **2020.01** | + | Version : **2023.02** |
Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
- | ====== | + | ====== |
- | =====LAB #5 - Débuter avec Ansible===== | + | =====Contenu du Module===== |
- | ====La Commande ansible==== | + | * **LCF802 - Les Commandes ansible, ansible-playbook et ansible-galaxy** |
+ | * Contenu du Module | ||
+ | * LAB #1 - Débuter avec Ansible | ||
+ | * 1.1 - La Commande ansible | ||
+ | * LAB #2 - La Commande ansible-playbook | ||
+ | * 2.1 - Playbook Files | ||
+ | * 2.2 - Tasks | ||
+ | * 2.3 - Handlers | ||
+ | * 2.4 - Modules | ||
+ | * 2.4.1 - Modules pour des Paquets | ||
+ | * 2.4.2 - Modules pour des Fichiers | ||
+ | * 2.4.3 - Modules pour le Système | ||
+ | * 2.5 - Inventory Files | ||
+ | * 2.6 - Privilèges | ||
+ | * 2.6.1 - Création de Groupes | ||
+ | * LAB #3 - La Commande ansible-galaxy | ||
+ | * 3.1 - Utiliser des Rôles avec un Play Book | ||
+ | * 3.2 - Ansible Galaxy | ||
+ | |||
+ | =====LAB #1 - Débuter avec Ansible===== | ||
+ | |||
+ | ====1.1 - La Commande ansible==== | ||
Utilisez la commande **ansible** pour vérifier si la machine **TargetA** fonctionne : | Utilisez la commande **ansible** pour vérifier si la machine **TargetA** fonctionne : | ||
< | < | ||
- | trainee@ansible:~$ ansible all -i 10.0.2.10, -m ping | + | [trainee@centos8 |
- | [WARNING]: Platform linux on host 10.0.2.10 is using the discovered Python interpreter at / | + | 10.0.2.52 | SUCCESS => { |
- | change this. See https:// | + | |
- | 10.0.2.10 | + | |
" | " | ||
" | " | ||
Ligne 24: | Ligne 43: | ||
" | " | ||
} | } | ||
- | |||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Cette commande indique à Ansible qu' | **Important** : Cette commande indique à Ansible qu' | ||
</ | </ | ||
Ligne 34: | Ligne 52: | ||
< | < | ||
- | trainee@ansible:~$ ansible --help | + | [trainee@centos8 |
- | Usage: ansible | + | usage: ansible |
+ | | ||
+ | [-l SUBSET] [-P POLL_INTERVAL] [-B SECONDS] [-o] [-t TREE] [-k] | ||
+ | | ||
+ | [-c CONNECTION] [-T TIMEOUT] | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | [-e EXTRA_VARS] [--vault-id VAULT_IDS] | ||
+ | | ||
+ | [-f FORKS] [-M MODULE_PATH] [--playbook-dir BASEDIR] | ||
+ | | ||
+ | | ||
Define and run a single task ' | Define and run a single task ' | ||
- | Options: | + | positional arguments: |
- | -a MODULE_ARGS, --args=MODULE_ARGS | + | pattern |
- | | + | |
- | --ask-vault-pass | + | optional arguments: |
- | -B SECONDS, --background=SECONDS | + | --ask-vault-password, |
+ | ask for vault password | ||
+ | --list-hosts | ||
+ | anything else | ||
+ | --playbook-dir BASEDIR | ||
+ | Since this tool does not use playbooks, use this as a | ||
+ | substitute playbook directory.This sets the relative | ||
+ | path for many features including roles/ group_vars/ | ||
+ | etc. | ||
+ | | ||
+ | | ||
+ | --task-timeout TASK_TIMEOUT | ||
+ | set task timeout limit in seconds, must be positive | ||
+ | integer. | ||
+ | --vault-id VAULT_IDS | ||
+ | --vault-password-file VAULT_PASSWORD_FILES, | ||
+ | | ||
+ | --version | ||
+ | configured module search path, module location, | ||
+ | executable location and exit | ||
+ | -B SECONDS, --background SECONDS | ||
run asynchronously, | run asynchronously, | ||
(default=N/ | (default=N/ | ||
Ligne 50: | Ligne 101: | ||
-D, --diff | -D, --diff | ||
differences in those files; works great with --check | differences in those files; works great with --check | ||
- | -e EXTRA_VARS, --extra-vars=EXTRA_VARS | + | |
+ | prepend colon-separated path(s) to module library (def | ||
+ | ault=~/ | ||
+ | gins/ | ||
+ | -P POLL_INTERVAL, | ||
+ | set the poll interval if using -B (default=15) | ||
+ | -a MODULE_ARGS, | ||
+ | The action' | ||
+ | ' | ||
+ | | ||
set additional variables as key=value or YAML/JSON, if | set additional variables as key=value or YAML/JSON, if | ||
filename prepend with @ | filename prepend with @ | ||
- | -f FORKS, --forks=FORKS | + | -f FORKS, --forks FORKS |
specify number of parallel processes to use | specify number of parallel processes to use | ||
(default=5) | (default=5) | ||
-h, --help | -h, --help | ||
- | -i INVENTORY, --inventory=INVENTORY, --inventory-file=INVENTORY | + | -i INVENTORY, --inventory INVENTORY, --inventory-file INVENTORY |
specify inventory host path or comma separated host | specify inventory host path or comma separated host | ||
list. --inventory-file is deprecated | list. --inventory-file is deprecated | ||
- | -l SUBSET, --limit=SUBSET | + | -l SUBSET, --limit SUBSET |
further limit selected hosts to an additional pattern | further limit selected hosts to an additional pattern | ||
- | | + | -m MODULE_NAME, |
- | anything else | + | |
- | | + | |
- | | + | |
- | -M MODULE_PATH, | + | |
- | prepend colon-separated path(s) to module library | + | |
- | (default=['/ | + | |
- | '/ | + | |
-o, --one-line | -o, --one-line | ||
- | | + | -t TREE, --tree TREE log output to this directory |
- | Since this tool does not use playbooks, use this as a | + | |
- | subsitute playbook directory.This sets the relative | + | |
- | path for many features including roles/ group_vars/ | + | |
- | etc. | + | |
- | -P POLL_INTERVAL, | + | |
- | set the poll interval if using -B (default=15) | + | |
- | --syntax-check | + | |
- | execute it | + | |
- | | + | |
- | --vault-id=VAULT_IDS | + | |
- | --vault-password-file=VAULT_PASSWORD_FILES | + | |
- | vault password file | + | |
-v, --verbose | -v, --verbose | ||
connection debugging) | connection debugging) | ||
- | --version | ||
- | Connection | + | Privilege Escalation |
- | control | + | control how and which user you become as on target |
- | | + | |
- | --private-key=PRIVATE_KEY_FILE, | + | privilege escalation method to use (default=sudo), |
+ | `ansible-doc -t become -l` to list valid choices. | ||
+ | --become-user BECOME_USER | ||
+ | run operations as this user (default=root) | ||
+ | -K, --ask-become-pass | ||
+ | | ||
+ | -b, --become | ||
+ | prompting) | ||
+ | |||
+ | Connection Options: | ||
+ | control as whom and how to connect to hosts | ||
+ | |||
+ | | ||
use this file to authenticate the connection | use this file to authenticate the connection | ||
- | | + | |
- | connect as this user (default=None) | + | specify |
- | -c CONNECTION, --connection=CONNECTION | + | --sftp-extra-args SFTP_EXTRA_ARGS |
- | connection type to use (default=smart) | + | |
- | -T TIMEOUT, --timeout=TIMEOUT | + | |
- | override the connection timeout in seconds | + | |
- | (default=10) | + | |
- | --ssh-common-args=SSH_COMMON_ARGS | + | |
- | specify | + | |
- | ProxyCommand) | + | |
- | --sftp-extra-args=SFTP_EXTRA_ARGS | + | |
specify extra arguments to pass to sftp only (e.g. -f, | specify extra arguments to pass to sftp only (e.g. -f, | ||
-l) | -l) | ||
- | | + | |
- | specify | + | specify |
- | --ssh-extra-args=SSH_EXTRA_ARGS | + | ProxyCommand) |
+ | --ssh-extra-args SSH_EXTRA_ARGS | ||
specify extra arguments to pass to ssh only (e.g. -R) | specify extra arguments to pass to ssh only (e.g. -R) | ||
+ | -T TIMEOUT, --timeout TIMEOUT | ||
+ | override the connection timeout in seconds | ||
+ | (default=10) | ||
+ | -c CONNECTION, --connection CONNECTION | ||
+ | connection type to use (default=smart) | ||
+ | -k, --ask-pass | ||
+ | -u REMOTE_USER, | ||
+ | connect as this user (default=None) | ||
- | Privilege Escalation Options: | + | Some actions |
- | control how and which user you become as on target hosts | + | |
- | + | ||
- | -s, --sudo | + | |
- | become) | + | |
- | -U SUDO_USER, --sudo-user=SUDO_USER | + | |
- | desired sudo user (default=root) (deprecated, | + | |
- | become) | + | |
- | -S, --su run operations with su (deprecated, | + | |
- | -R SU_USER, --su-user=SU_USER | + | |
- | run operations with su as this user (default=None) | + | |
- | (deprecated, | + | |
- | -b, --become | + | |
- | prompting) | + | |
- | --become-method=BECOME_METHOD | + | |
- | privilege escalation method to use (default=sudo), | + | |
- | valid choices: [ sudo | su | pbrun | pfexec | doas | | + | |
- | dzdo | ksu | runas | pmrun | enable | machinectl ] | + | |
- | --become-user=BECOME_USER | + | |
- | run operations as this user (default=root) | + | |
- | --ask-sudo-pass | + | |
- | --ask-su-pass | + | |
- | -K, --ask-become-pass | + | |
- | ask for privilege escalation password | + | |
- | + | ||
- | Some modules | + | |
</ | </ | ||
- | Démarrez maintenant les quatre machines **Web01**, **Web02**, **Web03** et **Web04**. Si vous participez | + | Les quatre machines **WebXX** mises à votre disposition |
- | + | ||
- | < | + | |
- | trainee@ansible: | + | |
- | déconnexion | + | |
- | Connection to localhost closed. | + | |
- | desktop@server16: | + | |
- | Waiting for VM " | + | |
- | VM " | + | |
- | desktop@server16: | + | |
- | Waiting for VM " | + | |
- | VM " | + | |
- | desktop@server16: | + | |
- | Waiting for VM " | + | |
- | VM " | + | |
- | desktop@server16: | + | |
- | Waiting for VM " | + | |
- | VM " | + | |
- | desktop@server16: | + | |
- | trainee@localhost' | + | |
- | Linux ansible.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: Sun Apr 12 07:42:09 2020 from 10.0.2.2 | + | |
- | trainee@ansible: | + | |
- | </ | + | |
- | + | ||
- | Rappelez-vous que les quatre machines virtuelles **WebXX** importées | + | |
^ Machine ^ Nom d' | ^ Machine ^ Nom d' | ||
- | | Web01 | web01.i2tch.loc | 10.0.2.11 | | + | | Web01 | web01.i2tch.loc | 10.0.2.54 | |
- | | Web02 | web02.i2tch.loc | 10.0.2.12 | | + | | Web02 | web02.i2tch.loc | 10.0.2.55 | |
- | | Web03 | web03.i2tch.loc | 10.0.2.13 | | + | | Web03 | web03.i2tch.loc | 10.0.2.56 | |
- | | Web04 | web04.i2tch.loc | 10.0.2.14 | | + | | Web04 | web04.i2tch.loc | 10.0.2.57 | |
- | + | ||
- | Modifiez le fichier **/ | + | |
- | + | ||
- | < | + | |
- | trainee@ansible: | + | |
- | Mot de passe : fenestros | + | |
- | root@ansible: | + | |
- | root@ansible: | + | |
- | 127.0.0.1 localhost | + | |
- | 127.0.1.1 ansible.i2tch.loc | + | |
- | 10.0.2.9 ansible.i2tch.loc | + | |
- | 10.0.2.10 | + | |
- | 10.0.2.11 web01.i2tch.loc web01 | + | |
- | 10.0.2.12 web02.i2tch.loc web02 | + | |
- | 10.0.2.13 web03.i2tch.loc web03 | + | |
- | 10.0.2.14 web04.i2tch.loc web04 | + | |
- | + | ||
- | # The following lines are desirable for IPv6 capable hosts | + | |
- | ::1 | + | |
- | ff02::1 ip6-allnodes | + | |
- | ff02::2 ip6-allrouters | + | |
- | root@ansible: | + | |
- | déconnexion | + | |
- | trainee@ansible: | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round important 60%> | + | |
- | **Important** : Notez que le mot de passe **fenestros** ne sera pas en clair. | + | |
- | </ | + | |
Utilisez la commande **scp** pour copier le fichier **authorized_keys** de la machine virtuelle **ansible** vers les machines virtuelles **Web01**, **Web02**, **Web03** et **Web04** : | Utilisez la commande **scp** pour copier le fichier **authorized_keys** de la machine virtuelle **ansible** vers les machines virtuelles **Web01**, **Web02**, **Web03** et **Web04** : | ||
< | < | ||
- | trainee@ansible:~$ scp .ssh/ | + | [trainee@centos8 |
- | The authenticity of host 'web01.i2tch.loc (10.0.2.11)' can't be established. | + | The authenticity of host '10.0.2.54 (10.0.2.54)' can't be established. |
ECDSA key fingerprint is SHA256: | ECDSA key fingerprint is SHA256: | ||
- | Are you sure you want to continue connecting (yes/no)? yes | + | Are you sure you want to continue connecting (yes/no/ |
- | Warning: Permanently added 'web01.i2tch.loc, | + | Warning: Permanently added ' |
Debian GNU/Linux 9 | Debian GNU/Linux 9 | ||
- | trainee@web01.i2tch.loc's password: | + | trainee@10.0.2.54's password: |
- | authorized_keys | + | authorized_keys |
- | trainee@ansible:~$ scp .ssh/ | + | |
- | The authenticity of host 'web02.i2tch.loc (10.0.2.12)' can't be established. | + | [trainee@centos8 |
+ | The authenticity of host '10.0.2.55 (10.0.2.55)' can't be established. | ||
ECDSA key fingerprint is SHA256: | ECDSA key fingerprint is SHA256: | ||
- | Are you sure you want to continue connecting (yes/no)? yes | + | Are you sure you want to continue connecting (yes/no/ |
- | Warning: Permanently added 'web02.i2tch.loc, | + | Warning: Permanently added ' |
Debian GNU/Linux 9 | Debian GNU/Linux 9 | ||
- | trainee@web02.i2tch.loc's password: | + | trainee@10.0.2.55's password: |
- | authorized_keys | + | authorized_keys |
- | trainee@ansible:~$ scp .ssh/ | + | |
- | The authenticity of host 'web03.i2tch.loc (10.0.2.13)' can't be established. | + | [trainee@centos8 |
+ | The authenticity of host '10.0.2.56 (10.0.2.56)' can't be established. | ||
ECDSA key fingerprint is SHA256: | ECDSA key fingerprint is SHA256: | ||
- | Are you sure you want to continue connecting (yes/no)? yes | + | Are you sure you want to continue connecting (yes/no/ |
- | Warning: Permanently added 'web03.i2tch.loc, | + | Warning: Permanently added ' |
Debian GNU/Linux 9 | Debian GNU/Linux 9 | ||
- | trainee@web03.i2tch.loc's password: | + | trainee@10.0.2.56's password: |
- | authorized_keys | + | authorized_keys |
- | trainee@ansible:~$ scp .ssh/ | + | |
- | The authenticity of host 'web04.i2tch.loc (10.0.2.14)' can't be established. | + | [trainee@centos8 |
+ | The authenticity of host '10.0.2.57 (10.0.2.57)' can't be established. | ||
ECDSA key fingerprint is SHA256: | ECDSA key fingerprint is SHA256: | ||
- | Are you sure you want to continue connecting (yes/no)? yes | + | Are you sure you want to continue connecting (yes/no/ |
- | Warning: Permanently added 'web04.i2tch.loc, | + | Warning: Permanently added ' |
Debian GNU/Linux 9 | Debian GNU/Linux 9 | ||
- | trainee@web04.i2tch.loc's password: | + | trainee@10.0.2.57's password: |
- | authorized_keys | + | authorized_keys |
</ | </ | ||
- | Vérifiez que vous pouvez vous connecter aux machines virtuelles | + | Modifier le fichier |
< | < | ||
- | trainee@ansible:~$ ssh -l trainee web01 | + | [trainee@centos8 ~]$ su - |
+ | Password: fenestros | ||
+ | [root@centos8 ~]# vi / | ||
+ | [root@centos8 ~]# cat / | ||
+ | 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 | ||
+ | [root@centos8 ~]# exit | ||
+ | logout | ||
+ | [trainee@centos8 ~]$ | ||
+ | </ | ||
+ | |||
+ | Vérifiez que vous pouvez vous connecter aux machines virtuelles **Web01**, **Web02**, **Web03** et **Web04** sans entrer de mot de passe et que la configuration de sudo est correcte : | ||
+ | |||
+ | < | ||
+ | [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 259: | 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: | + | Last login: |
+ | trainee@web01: | ||
+ | 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 32s (638 ko/s) | ||
+ | Lecture des listes de paquets... Fait | ||
+ | Construction de l' | ||
+ | Lecture des informations d' | ||
+ | 341 packages can be upgraded. Run 'apt list --upgradable' | ||
trainee@web01: | trainee@web01: | ||
déconnexion | déconnexion | ||
Connection to web01 closed. | Connection to web01 closed. | ||
- | trainee@ansible:~$ ssh -l trainee web02 | + | [trainee@centos8 |
- | The authenticity of host 'web02 (10.0.2.12)' | + | |
- | ECDSA key fingerprint is SHA256: | + | |
- | Are you sure you want to continue connecting (yes/no)? yes | + | |
- | Warning: Permanently added ' | + | |
Debian GNU/Linux 9 | Debian GNU/Linux 9 | ||
Linux web02.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 | Linux web02.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 | ||
Ligne 277: | Ligne 280: | ||
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: | + | Last login: |
+ | trainee@web02: | ||
+ | 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 32s (639 ko/s) | ||
+ | Lecture des listes de paquets... Fait | ||
+ | Construction de l' | ||
+ | Lecture des informations d' | ||
+ | 341 packages can be upgraded. Run 'apt list --upgradable' | ||
trainee@web02: | trainee@web02: | ||
déconnexion | déconnexion | ||
Connection to web02 closed. | Connection to web02 closed. | ||
- | trainee@ansible:~$ ssh -l trainee web03 | + | [trainee@centos8 |
- | The authenticity of host 'web03 (10.0.2.13)' | + | |
- | ECDSA key fingerprint is SHA256: | + | |
- | Are you sure you want to continue connecting (yes/no)? yes | + | |
- | Warning: Permanently added ' | + | |
Debian GNU/Linux 9 | 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 | Linux web03.i2tch.loc 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 | ||
Ligne 295: | Ligne 311: | ||
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: | + | Last login: |
+ | trainee@web03: | ||
+ | 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 40s (524 ko/s) | ||
+ | Lecture des listes de paquets... Fait | ||
+ | Construction de l' | ||
+ | Lecture des informations d' | ||
+ | 341 packages can be upgraded. Run 'apt list --upgradable' | ||
trainee@web03: | trainee@web03: | ||
déconnexion | déconnexion | ||
Connection to web03 closed. | Connection to web03 closed. | ||
- | trainee@ansible:~$ ssh -l trainee web04 | + | [trainee@centos8 |
- | The authenticity of host 'web04 (10.0.2.14)' | + | |
- | ECDSA key fingerprint is SHA256: | + | |
- | Are you sure you want to continue connecting (yes/no)? yes | + | |
- | Warning: Permanently added ' | + | |
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 313: | Ligne 342: | ||
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: | + | Last login: |
+ | trainee@web04: | ||
+ | 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 39s (535 ko/s) | ||
+ | Lecture des listes de paquets... Fait | ||
+ | Construction de l' | ||
+ | Lecture des informations d' | ||
+ | 341 packages can be upgraded. Run 'apt list --upgradable' | ||
+ | trainee@web04: | ||
+ | déconnexion | ||
+ | Connection to web04 closed. | ||
+ | [trainee@centos8 ~]$ | ||
</ | </ | ||
- | Utilisez ensuite la commende | + | Utilisez ensuite la commande |
< | < | ||
- | trainee@ansible:~$ ansible all -i web01, -m ping | + | [trainee@centos8 |
- | [WARNING]: Platform linux on host web01 is using the discovered Python interpreter at / | + | 10.0.2.54 | SUCCESS => { |
- | change this. See https:// | + | |
- | web01 | SUCCESS => { | + | |
" | " | ||
" | " | ||
Ligne 329: | Ligne 377: | ||
" | " | ||
} | } | ||
- | trainee@ansible:~$ ansible all -i web02, -m ping | + | [trainee@centos8 |
- | [WARNING]: Platform linux on host web02 is using the discovered Python interpreter at / | + | 10.0.2.55 | SUCCESS => { |
- | change this. See https:// | + | |
- | web02 | SUCCESS => { | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | trainee@ansible: | + | |
- | [WARNING]: Platform linux on host web03 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
- | web03 | SUCCESS => { | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | trainee@ansible: | + | |
- | [WARNING]: Platform linux on host web04 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
- | web04 | SUCCESS => { | + | |
" | " | ||
" | " | ||
Ligne 364: | Ligne 390: | ||
< | < | ||
- | trainee@ansible:~$ ansible all -i web01, | + | [trainee@centos8 |
- | [WARNING]: Platform linux on host web04 is using the discovered Python interpreter at / | + | web02 | SUCCESS => { |
- | change this. See https:// | + | |
- | web04 | SUCCESS => { | + | |
" | " | ||
" | " | ||
Ligne 374: | Ligne 398: | ||
" | " | ||
} | } | ||
- | [WARNING]: Platform linux on host web01 is using the discovered Python interpreter at / | ||
- | change this. See https:// | ||
web01 | SUCCESS => { | web01 | SUCCESS => { | ||
" | " | ||
Ligne 383: | Ligne 405: | ||
" | " | ||
} | } | ||
- | [WARNING]: Platform linux on host web03 is using the discovered Python interpreter at / | ||
- | change this. See https:// | ||
web03 | SUCCESS => { | web03 | SUCCESS => { | ||
" | " | ||
Ligne 392: | Ligne 412: | ||
" | " | ||
} | } | ||
- | [WARNING]: Platform linux on host web02 is using the discovered Python interpreter at / | + | web04 | SUCCESS => { |
- | change this. See https:// | + | |
- | web02 | SUCCESS => { | + | |
" | " | ||
" | " | ||
Ligne 403: | Ligne 421: | ||
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que les résultats ne sont pas retournés dans un ordre séquentiel par rapport à la commande exécutée. En effet, ansible a paralléliser l' | **Important** : Notez que les résultats ne sont pas retournés dans un ordre séquentiel par rapport à la commande exécutée. En effet, ansible a paralléliser l' | ||
</ | </ | ||
Ligne 410: | Ligne 428: | ||
< | < | ||
- | trainee@ansible:~$ ansible all -i web01, | + | [trainee@centos8 |
- | [WARNING]: Platform linux on host web03 is using the discovered Python interpreter at / | + | web02 | CHANGED | rc=0 >> |
- | change this. See https:// | + | 11:40:49 up 18:26, 1 user, load average: 0,24, 0,11, 0,03 |
web03 | CHANGED | rc=0 >> | web03 | CHANGED | rc=0 >> | ||
- | 10:49:07 up 51 min, 1 user, load average: 0,00, 0,00, 0,00 | + | 11:40:49 up 18:26, 1 user, load average: 0,10, 0,03, 0,01 |
- | [WARNING]: Platform linux on host web01 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
web01 | CHANGED | rc=0 >> | web01 | CHANGED | rc=0 >> | ||
- | 10:49:07 up 52 min, 1 user, load average: 0,00, 0,00, 0,00 | + | 11:40:49 up 18:26, 1 user, load average: 0,00, 0,00, 0,00 |
- | [WARNING]: Platform linux on host web04 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
web04 | CHANGED | rc=0 >> | web04 | CHANGED | rc=0 >> | ||
- | 10:49:07 up 51 min, 1 user, load average: 0,00, 0,00, 0,00 | + | 11:40:49 up 18:26, 1 user, load average: 0,00, 0,00, 0,00 |
- | [WARNING]: Platform linux on host web02 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
- | web02 | CHANGED | rc=0 >> | + | |
- | | + | |
</ | </ | ||
- | Exécutez ensuite une commande pour installer **apache2** dans les machines web01, web02, web03 et web04 en utilisant le module **command**. Vous devez voire la confirmation que le paquet a déjà été installé - **apache2 is already the newest version** : | + | =====LAB #2 - La Commande ansible-playbook===== |
- | + | ||
- | < | + | |
- | trainee@ansible: | + | |
- | [WARNING]: Consider using ' | + | |
- | [WARNING]: Platform linux on host web03 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
- | web03 | CHANGED | rc=0 >> | + | |
- | Lecture des listes de paquets… | + | |
- | Construction de l' | + | |
- | Lecture des informations d' | + | |
- | apache2 is already the newest version (2.4.25-3+deb9u6). | + | |
- | 0 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour. | + | |
- | [WARNING]: Platform linux on host web02 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
- | web02 | CHANGED | rc=0 >> | + | |
- | Lecture des listes de paquets… | + | |
- | Construction de l' | + | |
- | Lecture des informations d' | + | |
- | apache2 is already the newest version (2.4.25-3+deb9u6). | + | |
- | 0 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour. | + | |
- | [WARNING]: Platform linux on host web04 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
- | web04 | CHANGED | rc=0 >> | + | |
- | Lecture des listes de paquets… | + | |
- | Construction de l' | + | |
- | Lecture des informations d' | + | |
- | apache2 is already the newest version (2.4.25-3+deb9u6). | + | |
- | 0 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour. | + | |
- | [WARNING]: Platform linux on host web01 is using the discovered Python interpreter at / | + | |
- | change this. See https:// | + | |
- | web01 | CHANGED | rc=0 >> | + | |
- | Lecture des listes de paquets… | + | |
- | Construction de l' | + | |
- | Lecture des informations d' | + | |
- | apache2 is already the newest version (2.4.25-3+deb9u6). | + | |
- | 0 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour. | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round important 60%> | + | |
- | **Important** : Notez l' | + | |
- | </ | + | |
- | + | ||
- | =====LAB #6 - La Commande ansible-playbook===== | + | |
La commande **ansible-playbook** permet d’insérer la configuration d' | La commande **ansible-playbook** permet d’insérer la configuration d' | ||
- | ====Playbook Files==== | + | ====2.1 - Playbook Files==== |
Un Playbook File contient une liste de **Plays** qui regroupent des tâches, appelées des **tasks**. Chaque task est une commande à exécuter sur une machine cible : | Un Playbook File contient une liste de **Plays** qui regroupent des tâches, appelées des **tasks**. Chaque task est une commande à exécuter sur une machine cible : | ||
+ | |||
+ | {{ : | ||
{{ : | {{ : | ||
+ | |||
+ | {{ : | ||
Dans l' | Dans l' | ||
Ligne 508: | Ligne 479: | ||
* Le mot clef **tasks:** contient une autre liste YAML qui spécifie les tâches à effectuer. | * Le mot clef **tasks:** contient une autre liste YAML qui spécifie les tâches à effectuer. | ||
- | ===Tasks=== | + | ====2.2 - Tasks==== |
Un task est une tâche individuelle qui doit être accomplie : | Un task est une tâche individuelle qui doit être accomplie : | ||
Ligne 528: | Ligne 499: | ||
* Le **module** Ansible **group** est un dictionnaire YAML qui contient deux champs - **name** et **state**. | * Le **module** Ansible **group** est un dictionnaire YAML qui contient deux champs - **name** et **state**. | ||
- | ===Handlers=== | + | ====2.3 - Handlers==== |
Un **Handler** est une tâche **conditionnelle** : | Un **Handler** est une tâche **conditionnelle** : | ||
Ligne 569: | Ligne 540: | ||
* Dans le cas contraire, le handler n'est pas appelé. | * Dans le cas contraire, le handler n'est pas appelé. | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que les handlers sont appelés **après** l' | **Important** : Notez que les handlers sont appelés **après** l' | ||
</ | </ | ||
- | ===Modules=== | + | ====2.4 - Modules==== |
- | La liste complète des modules se trouve à **[[http:// | + | La liste complète des modules se trouve à **[[https:// |
- | ==Modules pour des Paquets== | + | ===2.4.1 - Modules pour des Paquets=== |
* Le **module** Ansible **package** est généralement une valeur scalaire qui contient une chaîne qui stipule le paquet à installer ou bien un dictionnaire. Le contenu est composé de deux paramètres - **name** et **state**. Dans le cas de ce module la valeur du paramètre **state** peut être **latest**, **present**, | * Le **module** Ansible **package** est généralement une valeur scalaire qui contient une chaîne qui stipule le paquet à installer ou bien un dictionnaire. Le contenu est composé de deux paramètres - **name** et **state**. Dans le cas de ce module la valeur du paramètre **state** peut être **latest**, **present**, | ||
Ligne 583: | Ligne 554: | ||
* Le **module** Ansible **gem** est décrit par deux paramètres - **name** et **state**. Dans le cas de ce module la valeur du paramètre **state** est similaire à celle du module package. | * Le **module** Ansible **gem** est décrit par deux paramètres - **name** et **state**. Dans le cas de ce module la valeur du paramètre **state** est similaire à celle du module package. | ||
- | ==Modules pour des Fichiers== | + | ===2.4.2 - Modules pour des Fichiers=== |
* Le **module** Ansible **copy** copie un fichier du contrôleur vers un système distant. Ce module peut vérifier les propriétés du fichier telles son contenu, le propriétaire avec **owner:**, le groupe avec **group:** ou les permissions avec **0644**, | * Le **module** Ansible **copy** copie un fichier du contrôleur vers un système distant. Ce module peut vérifier les propriétés du fichier telles son contenu, le propriétaire avec **owner:**, le groupe avec **group:** ou les permissions avec **0644**, | ||
Ligne 591: | Ligne 562: | ||
* Le **module** Ansible **unarchive** désarchive une archive sur le système distant. Avant de désarchiver l' | * Le **module** Ansible **unarchive** désarchive une archive sur le système distant. Avant de désarchiver l' | ||
- | ==Modules pour le Système== | + | ===2.4.3 - Modules pour le Système=== |
Les modules les plus importants dans cette catégorie sont : | Les modules les plus importants dans cette catégorie sont : | ||
Ligne 600: | Ligne 571: | ||
* **group**. | * **group**. | ||
- | ====Inventory Files==== | + | ====2.5 - Inventory Files==== |
Un Ansible Inventory File : | Un Ansible Inventory File : | ||
Ligne 606: | Ligne 577: | ||
* contrôle quels systèmes sont ciblés par ansible-playbook, | * contrôle quels systèmes sont ciblés par ansible-playbook, | ||
* permet des configurations par système, | * permet des configurations par système, | ||
- | * est un fichier au format INI, | + | * est un fichier au format INI. |
- | * est stocké | + | |
+ | L' | ||
Dans un tel fichier, on peut trouver des listes simples : | Dans un tel fichier, on peut trouver des listes simples : | ||
Ligne 638: | Ligne 610: | ||
</ | </ | ||
- | Par exemple, l' | + | Par exemple, l' |
< | < | ||
... | ... | ||
- | web01 ansible_hostname=10.0.2.11 ansible_user=trainee | + | web01 ansible_hostname=10.0.2.54 ansible_user=trainee |
... | ... | ||
- | web02 ansible_hostname=10.0.2.12 ansible_user=trainee | + | web02 ansible_hostname=10.0.2.55 ansible_user=trainee |
... | ... | ||
- | web03 ansible_hostname=10.0.2.13 ansible_user=trainee | + | web03 ansible_hostname=10.0.2.56 ansible_user=trainee |
... | ... | ||
- | web04 ansible_hostname=10.0.2.14 ansible_user=trainee | + | web04 ansible_hostname=10.0.2.57 ansible_user=trainee |
... | ... | ||
</ | </ | ||
- | ===Privilèges=== | + | ====2.6 - Privilèges==== |
Ansible a besoin d' | Ansible a besoin d' | ||
Ligne 666: | Ligne 638: | ||
* **Docker** - la commande docker exec. La configuration est effectuée par Ansible au lieu d'un DockerFile traditionnel. | * **Docker** - la commande docker exec. La configuration est effectuée par Ansible au lieu d'un DockerFile traditionnel. | ||
- | ===Création de Groupes=== | + | ===2.6.1 - Création de Groupes=== |
Ansible permet le regroupement d' | Ansible permet le regroupement d' | ||
Ligne 702: | Ligne 674: | ||
[debian: | [debian: | ||
- | web | + | apache |
nginx | nginx | ||
Ligne 752: | Ligne 724: | ||
Dans cet exemple, la valeur du mot clef **hosts:** est le nom d'un groupe. | Dans cet exemple, la valeur du mot clef **hosts:** est le nom d'un groupe. | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez qu'il existe un groupe spécial appelé **all**. Ce groupe n'a pas besoin d' | **Important** : Notez qu'il existe un groupe spécial appelé **all**. Ce groupe n'a pas besoin d' | ||
</ | </ | ||
- | Dans la machine virtuelle | + | Dans la machine virtuelle |
< | < | ||
- | trainee@ansible:~$ vi inventory | + | [trainee@centos8 |
- | trainee@ansible:~$ cat inventory | + | [trainee@centos8 |
[basededonnees] | [basededonnees] | ||
web01 | web01 | ||
Ligne 783: | Ligne 755: | ||
< | < | ||
- | trainee@ansible:~$ vi playbook.yaml | + | [trainee@centos8 |
- | trainee@ansible:~$ cat playbook.yaml | + | [trainee@centos8 |
--- | --- | ||
- hosts: basededonnees | - hosts: basededonnees | ||
Ligne 790: | Ligne 762: | ||
tasks: | tasks: | ||
- name: install | - name: install | ||
- | package: name=postgresql state=installed | + | package: name=postgresql state=present |
- name: service | - name: service | ||
service: name=postgresql state=started enabled=yes | service: name=postgresql state=started enabled=yes | ||
Ligne 798: | Ligne 770: | ||
tasks: | tasks: | ||
- name: install jre | - name: install jre | ||
- | package: name=openjdk-8-jre state=installed | + | package: name=openjdk-8-jre state=present |
- hosts: equilibrage | - hosts: equilibrage | ||
become: true | become: true | ||
tasks: | tasks: | ||
- name: install | - name: install | ||
- | package: name=haproxy | + | package: name=haproxy |
- name: service | - name: service | ||
service: name=haproxy state=started enabled=yes | service: name=haproxy state=started enabled=yes | ||
Ligne 812: | Ligne 784: | ||
< | < | ||
- | trainee@ansible:~$ ansible-playbook -i inventory playbook.yaml | + | [trainee@centos8 |
- | PLAY [basededonnees] ********************************************************************************************************************************************************* | + | PLAY [basededonnees] |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [Gathering Facts] |
ok: [web01] | ok: [web01] | ||
- | TASK [install] ********************************************************************************************************************************************************** | + | TASK [install] *************************************************************************************************************************************************************************************************** |
- | [DEPRECATION WARNING]: State ' | + | |
- | disabled by setting deprecation_warnings=False in ansible.cfg. | + | |
changed: [web01] | changed: [web01] | ||
- | TASK [service] ********************************************************************************************************************************************************** | + | TASK [service] |
ok: [web01] | ok: [web01] | ||
- | PLAY [dotcms] *********************************************************************************************************************************************************** | + | PLAY [dotcms] **************************************************************************************************************************************************************************************************** |
- | + | TASK [Gathering Facts] ******************************************************************************************************************************************************************************************* | |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | |
- | ok: [web03] | + | |
ok: [web02] | ok: [web02] | ||
- | |||
- | TASK [install jre] ****************************************************************************************************************************************************** | ||
ok: [web03] | ok: [web03] | ||
- | ok: [web02] | ||
- | PLAY [equilibrage] ********************************************************************************************************************************************************* | + | TASK [install jre] *********************************************************************************************************************************************************************************************** |
- | + | ||
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | |
- | ok: [web04] | + | |
- | + | ||
- | TASK [install] ********************************************************************************************************************************************************** | + | |
- | fatal: [web04]: FAILED! => {" | + | |
- | to retry, use: --limit @/ | + | |
- | + | ||
- | PLAY RECAP ************************************************************************************************************************************************************** | + | |
- | web01 : ok=3 changed=1 | + | |
- | web02 : ok=2 changed=0 | + | |
- | web03 : ok=2 changed=0 | + | |
- | web04 : ok=1 changed=0 | + | |
- | </ | + | |
- | + | ||
- | Notez l’avertissement ainsi que l' | + | |
- | + | ||
- | <WRAP center round important 60%> | + | |
- | **Important** : L' | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round important 60%> | + | |
- | **Important** : L' | + | |
- | </ | + | |
- | + | ||
- | En consultant le fichier playbook.yaml, | + | |
- | + | ||
- | < | + | |
- | trainee@ansible: | + | |
- | | + | |
- | 2 - hosts: basededonnees | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | 10 - hosts: dotcms | + | |
- | 11 become: true | + | |
- | 12 tasks: | + | |
- | 13 - name: install jre | + | |
- | 14 package: name=openjdk-8-jre state=installed | + | |
- | 15 - hosts: equilibrage | + | |
- | 16 become: true | + | |
- | 17 tasks: | + | |
- | 18 - name: install | + | |
- | 19 package: name=haproxy stated=installed | + | |
- | 20 - name: service | + | |
- | 21 service: name=haproxy state=started enabled=yes | + | |
- | 22 tags: service | + | |
- | </ | + | |
- | + | ||
- | Corrigez le fichier playbook.yaml aux lignes **6**, **14** et **19** et remplacez le mot **installed** par **present** : | + | |
- | + | ||
- | < | + | |
- | trainee@ansible: | + | |
- | trainee@ansible: | + | |
- | --- | + | |
- | - hosts: basededonnees | + | |
- | become: true | + | |
- | tasks: | + | |
- | - name: install | + | |
- | package: name=postgresql state=present | + | |
- | - name: service | + | |
- | service: name=postgresql state=started enabled=yes | + | |
- | tags: service | + | |
- | - hosts: dotcms | + | |
- | become: true | + | |
- | tasks: | + | |
- | - name: install jre | + | |
- | package: name=openjdk-8-jre state=present | + | |
- | - hosts: equilibrage | + | |
- | become: true | + | |
- | tasks: | + | |
- | - name: install | + | |
- | package: name=haproxy state=present | + | |
- | - name: service | + | |
- | service: name=haproxy state=started enabled=yes | + | |
- | tags: service | + | |
- | </ | + | |
- | + | ||
- | Ré-exécutez la commande **ansible-playbook** : | + | |
- | + | ||
- | < | + | |
- | trainee@ansible: | + | |
- | + | ||
- | PLAY [basededonnees] ********************************************************************************************************************************************************* | + | |
- | + | ||
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | |
- | ok: [web01] | + | |
- | + | ||
- | TASK [install] ********************************************************************************************************************************************************** | + | |
- | ok: [web01] | + | |
- | + | ||
- | TASK [service] ********************************************************************************************************************************************************** | + | |
- | ok: [web01] | + | |
- | + | ||
- | PLAY [dotcms] *********************************************************************************************************************************************************** | + | |
- | + | ||
- | TASK [Gathering Facts] | + | |
ok: [web03] | ok: [web03] | ||
ok: [web02] | ok: [web02] | ||
- | TASK [install jre] ****************************************************************************************************************************************************** | + | PLAY [equilibrage] *********************************************************************************************************************************************************************************************** |
- | ok: [web02] | + | |
- | ok: [web03] | + | |
- | + | ||
- | PLAY [equilibrage] | + | |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [Gathering Facts] |
ok: [web04] | ok: [web04] | ||
- | TASK [install] ********************************************************************************************************************************************************** | + | TASK [install] |
changed: [web04] | changed: [web04] | ||
- | TASK [service] ********************************************************************************************************************************************************** | + | TASK [service] |
ok: [web04] | ok: [web04] | ||
- | PLAY RECAP ************************************************************************************************************************************************************** | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
- | web01 : ok=3 changed=0 | + | web01 : ok=3 changed=1 |
- | web02 : ok=2 changed=0 | + | web02 : ok=2 changed=0 |
- | web03 : ok=2 changed=0 | + | web03 : ok=2 changed=0 |
- | web04 : ok=3 changed=1 | + | web04 : ok=3 changed=1 |
</ | </ | ||
- | |||
- | <WRAP center round important 60%> | ||
- | **Important** : Notez que seul **web04** a été modifié. | ||
- | </ | ||
Il est possible de limiter l' | Il est possible de limiter l' | ||
< | < | ||
- | trainee@ansible:~$ ansible-playbook -i inventory playbook.yaml -l equilibrage | + | [trainee@centos8 |
- | PLAY [basededonnees] ********************************************************************************************************************************************************* | + | PLAY [basededonnees] |
skipping: no hosts matched | skipping: no hosts matched | ||
- | PLAY [dotcms] *********************************************************************************************************************************************************** | + | PLAY [dotcms] |
skipping: no hosts matched | skipping: no hosts matched | ||
- | PLAY [equilibrage] ********************************************************************************************************************************************************* | + | PLAY [equilibrage] |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [Gathering Facts] |
ok: [web04] | ok: [web04] | ||
- | TASK [install] ********************************************************************************************************************************************************** | + | TASK [install] |
ok: [web04] | ok: [web04] | ||
- | TASK [service] ********************************************************************************************************************************************************** | + | TASK [service] |
ok: [web04] | ok: [web04] | ||
- | PLAY RECAP ************************************************************************************************************************************************************** | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
- | web04 : ok=3 changed=0 | + | web04 : ok=3 changed=0 |
</ | </ | ||
Ligne 997: | Ligne 853: | ||
< | < | ||
- | trainee@ansible:~$ ansible-playbook -i inventory playbook.yaml -l web04 | + | [trainee@centos8 |
- | PLAY [basededonnees] **************************************************************************************************************************************************** | + | PLAY [basededonnees] |
skipping: no hosts matched | skipping: no hosts matched | ||
- | PLAY [dotcms] *********************************************************************************************************************************************************** | + | PLAY [dotcms] |
skipping: no hosts matched | skipping: no hosts matched | ||
- | PLAY [equilibrage] ****************************************************************************************************************************************************** | + | PLAY [equilibrage] |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [Gathering Facts] |
ok: [web04] | ok: [web04] | ||
- | TASK [install] ********************************************************************************************************************************************************** | + | TASK [install] |
ok: [web04] | ok: [web04] | ||
- | TASK [service] ********************************************************************************************************************************************************** | + | TASK [service] |
ok: [web04] | ok: [web04] | ||
- | PLAY RECAP ************************************************************************************************************************************************************** | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
- | web04 : ok=3 changed=0 | + | web04 : ok=3 changed=0 |
</ | </ | ||
Ligne 1036: | Ligne 892: | ||
< | < | ||
- | trainee@ansible:~$ ansible-playbook -i inventory playbook.yaml --tags service | + | [trainee@centos8 |
- | PLAY [basededonnees] **************************************************************************************************************************************************** | + | PLAY [basededonnees] |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [Gathering Facts] |
ok: [web01] | ok: [web01] | ||
- | TASK [service] ********************************************************************************************************************************************************** | + | TASK [service] |
ok: [web01] | ok: [web01] | ||
- | PLAY [dotcms] *********************************************************************************************************************************************************** | + | PLAY [dotcms] |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [Gathering Facts] |
ok: [web02] | ok: [web02] | ||
ok: [web03] | ok: [web03] | ||
- | PLAY [equilibrage] ****************************************************************************************************************************************************** | + | PLAY [equilibrage] |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [Gathering Facts] |
ok: [web04] | ok: [web04] | ||
- | TASK [service] ********************************************************************************************************************************************************** | + | TASK [service] |
ok: [web04] | ok: [web04] | ||
- | PLAY RECAP ************************************************************************************************************************************************************** | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
- | web01 : ok=2 changed=0 | + | web01 : ok=2 changed=0 |
- | web02 : ok=1 changed=0 | + | web02 : ok=1 changed=0 |
- | web03 : ok=1 changed=0 | + | web03 : ok=1 changed=0 |
- | web04 : ok=2 changed=0 | + | web04 : ok=2 changed=0 |
</ | </ | ||
Ligne 1070: | Ligne 926: | ||
< | < | ||
- | trainee@ansible:~$ ansible-playbook -i inventory playbook.yaml --tags service -l equilibrage | + | [trainee@centos8 |
- | PLAY [basededonnees] **************************************************************************************************************************************************** | + | PLAY [basededonnees] |
skipping: no hosts matched | skipping: no hosts matched | ||
- | PLAY [dotcms] *********************************************************************************************************************************************************** | + | PLAY [dotcms] |
skipping: no hosts matched | skipping: no hosts matched | ||
- | PLAY [equilibrage] ****************************************************************************************************************************************************** | + | PLAY [equilibrage] |
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | TASK [Gathering Facts] |
ok: [web04] | ok: [web04] | ||
- | TASK [service] ********************************************************************************************************************************************************** | + | TASK [service] |
ok: [web04] | ok: [web04] | ||
- | PLAY RECAP ************************************************************************************************************************************************************** | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
- | web04 : ok=2 changed=0 | + | web04 : ok=2 changed=0 |
</ | </ | ||
- | =====LAB #7 - La Commande ansible-galaxy===== | + | =====LAB #3 - La Commande ansible-galaxy===== |
- | ====Utiliser des Rôles avec un Play Book==== | + | ====3.1 - Utiliser des Rôles avec un Play Book==== |
Les **Rôles** permettent la création d'une bibliothèque réutilisable. | Les **Rôles** permettent la création d'une bibliothèque réutilisable. | ||
+ | |||
+ | {{ : | ||
Un **Rôle** est un répertoire contenant les sous-répertoires suivants : | Un **Rôle** est un répertoire contenant les sous-répertoires suivants : | ||
Ligne 1113: | Ligne 971: | ||
* contient des variables de configuration de haute priorité, difficilement sur-chargées par des variables ailleurs. | * contient des variables de configuration de haute priorité, difficilement sur-chargées par des variables ailleurs. | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que seul le répertoire **tasks** est obligatoire. | **Important** : Notez que seul le répertoire **tasks** est obligatoire. | ||
</ | </ | ||
Ligne 1159: | Ligne 1017: | ||
</ | </ | ||
- | Dans le cas de l' | + | Dans le cas de l' |
< | < | ||
Ligne 1177: | Ligne 1035: | ||
</ | </ | ||
- | ====Ansible Galaxy==== | + | ====3.2 - Ansible Galaxy==== |
Ansible Galaxy est un dépôt de Rôles créées par des tierces personnes. Ce dépôt peut être consulté à l' | Ansible Galaxy est un dépôt de Rôles créées par des tierces personnes. Ce dépôt peut être consulté à l' | ||
- | {{ : | + | {{ : |
- | Recherchez le mot clef **java** : | + | Recherchez le mot clef **java** avec un premier filtre de type **Rôle** et un deuxième filtre de type **Download Count** : |
- | {{ : | + | {{ : |
- | + | ||
- | Appliquez le filtre **Download Count** : | + | |
- | + | ||
- | {{ : | + | |
Consultez la première dans la liste : | Consultez la première dans la liste : | ||
- | {{ : | + | {{ : |
Copiez la commande d' | Copiez la commande d' | ||
- | {{ : | + | {{ : |
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que la convention utilisée pour les noms est // | **Important** : Notez que la convention utilisée pour les noms est // | ||
</ | </ | ||
- | Dans la machine **Ansible**, collez la commande copiée et exécutez-la : | + | Dans la machine **centos8**, collez la commande copiée et exécutez-la : |
< | < | ||
- | trainee@ansible:~$ ansible-galaxy install geerlingguy.java | + | [trainee@centos8 |
+ | Starting galaxy role install process | ||
- downloading role ' | - downloading role ' | ||
- | - downloading role from https:// | + | - downloading role from https:// |
- extracting geerlingguy.java to / | - extracting geerlingguy.java to / | ||
- | - geerlingguy.java (1.9.5) was installed successfully | + | - geerlingguy.java (2.0.1) was installed successfully |
</ | </ | ||
- | Consultez maintenant | + | Installez le paquet **tree** et consultez |
< | < | ||
- | trainee@ansible:~$ su - | + | [trainee@centos8 |
- | Mot de passe : fenestros | + | Password: |
- | root@ansible:~# apt-get install | + | [root@centos8 |
- | ... | + | / |
- | root@ansible:~# exit | + | [root@centos8 |
- | trainee@ansible:~$ tree / | + | logout |
+ | [trainee@centos8 | ||
/ | / | ||
├── defaults | ├── defaults | ||
- | │ └── main.yml | + | │ |
├── LICENSE | ├── LICENSE | ||
├── meta | ├── meta | ||
- | │ └── main.yml | + | │ |
├── molecule | ├── molecule | ||
- | │ └── default | + | │ |
- | │ ├── | + | │ |
- | │ | + | │ |
- | │ | + | |
- | │ | + | |
- | │ | + | |
├── README.md | ├── README.md | ||
├── tasks | ├── tasks | ||
- | │ ├── main.yml | + | │ |
- | │ ├── setup-Debian.yml | + | │ |
- | │ ├── setup-FreeBSD.yml | + | │ |
- | │ └── setup-RedHat.yml | + | │ |
├── templates | ├── templates | ||
- | │ └── java_home.sh.j2 | + | │ |
└── vars | └── vars | ||
+ | ├── Debian-10.yml | ||
+ | ├── Debian-11.yml | ||
├── Debian-8.yml | ├── Debian-8.yml | ||
├── Debian-9.yml | ├── Debian-9.yml | ||
├── Fedora.yml | ├── Fedora.yml | ||
├── FreeBSD.yml | ├── FreeBSD.yml | ||
- | ├── RedHat-6.yml | ||
├── RedHat-7.yml | ├── RedHat-7.yml | ||
+ | ├── RedHat-8.yml | ||
├── Ubuntu-12.yml | ├── Ubuntu-12.yml | ||
├── Ubuntu-14.yml | ├── Ubuntu-14.yml | ||
├── Ubuntu-16.yml | ├── Ubuntu-16.yml | ||
- | | + | |
+ | └── Ubuntu-20.yml | ||
- | 8 directories, | + | 7 directories, |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
**Important** : Notez que dans ce cas il n'y a pas eu de dépendances. Par contre la commande **ansible-galaxy** sait résoudre et gérer les dépendances. | **Important** : Notez que dans ce cas il n'y a pas eu de dépendances. Par contre la commande **ansible-galaxy** sait résoudre et gérer les dépendances. | ||
</ | </ | ||
Ligne 1265: | Ligne 1121: | ||
< | < | ||
- | trainee@ansible:~$ vi playbook_java.yaml | + | [trainee@centos8 |
- | trainee@ansible:~$ cat playbook_java.yaml | + | [trainee@centos8 |
--- | --- | ||
- hosts: all | - hosts: all | ||
Ligne 1274: | Ligne 1130: | ||
</ | </ | ||
- | Exécutez la commande | + | Avant d’exécuter ce playbook, créez le fichier |
< | < | ||
- | trainee@ansible:~$ ansible-playbook -i inventory playbook_java.yaml | + | [trainee@centos8 ~]$ vi .ansible.cfg |
+ | [trainee@centos8 | ||
+ | [defaults] | ||
+ | deprecation_warnings=False | ||
+ | log_path = ./ansible.log | ||
+ | </ | ||
- | PLAY [all] ************************************************************************************************************************************************************** | + | <WRAP center round important> |
+ | **Important** : Le comportement d' | ||
+ | </ | ||
- | TASK [Gathering Facts] ************************************************************************************************************************************************** | + | Pour consultez l' |
+ | |||
+ | < | ||
+ | [trainee@centos8 ~]$ ansible-config list | more | ||
+ | ACTION_WARNINGS: | ||
+ | default: true | ||
+ | description: | ||
+ | action (module or action plugin), These warnings can be silenced by adjusting | ||
+ | this setting to False.] | ||
+ | env: | ||
+ | - {name: ANSIBLE_ACTION_WARNINGS} | ||
+ | ini: | ||
+ | - {key: action_warnings, | ||
+ | name: Toggle action warnings | ||
+ | type: boolean | ||
+ | version_added: | ||
+ | AGNOSTIC_BECOME_PROMPT: | ||
+ | default: true | ||
+ | description: | ||
+ | the command line supplied become method | ||
+ | env: | ||
+ | - {name: ANSIBLE_AGNOSTIC_BECOME_PROMPT} | ||
+ | ini: | ||
+ | - {key: agnostic_become_prompt, | ||
+ | name: Display an agnostic become prompt | ||
+ | type: boolean | ||
+ | version_added: | ||
+ | yaml: {key: privilege_escalation.agnostic_become_prompt} | ||
+ | ALLOW_WORLD_READABLE_TMPFILES: | ||
+ | default: false | ||
+ | deprecated: {alternatives: | ||
+ | version: ' | ||
+ | description: | ||
+ | plugin option : | ||
+ | still accepted with the shell plugin adding additional options, like variables.', | ||
+ | This message will be removed in 2.14.] | ||
+ | name: Allow world-readable temporary files | ||
+ | type: boolean | ||
+ | ANSIBLE_CONNECTION_PATH: | ||
+ | default: null | ||
+ | description: | ||
+ | will be checked before searching $PATH., 'If null, ansible will start with the | ||
+ | same directory as the ansible script.' | ||
+ | env: | ||
+ | - {name: ANSIBLE_CONNECTION_PATH} | ||
+ | ini: | ||
+ | - {key: ansible_connection_path, | ||
+ | name: Path of ansible-connection script | ||
+ | type: path | ||
+ | version_added: | ||
+ | yaml: {key: persistent_connection.ansible_connection_path} | ||
+ | ANSIBLE_COW_ACCEPTLIST: | ||
+ | default: [bud-frogs, bunny, cheese, daemon, default, dragon, elephant-in-snake, | ||
+ | elephant, eyes, hellokitty, kitty, luke-koala, meow, milk, moofasa, moose, ren, | ||
+ | sheep, small, stegosaurus, | ||
+ | udder, vader-koala, | ||
+ | description: | ||
+ | list if you want to enable all installed templates. | ||
+ | env: | ||
+ | - deprecated: {alternatives: | ||
+ | --More-- | ||
+ | </ | ||
+ | |||
+ | Exécutez maintenant la commande **ansible-playbook** : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 ~]$ ansible-playbook -i inventory playbook_java.yaml | ||
+ | |||
+ | PLAY [all] ******************************************************************************************************************************************************************************************************* | ||
+ | |||
+ | TASK [Gathering Facts] | ||
ok: [web04] | ok: [web04] | ||
- | ok: [web02] | ||
- | ok: [web03] | ||
ok: [web01] | ok: [web01] | ||
+ | ok: [web03] | ||
+ | ok: [web02] | ||
- | TASK [geerlingguy.java : Include OS-specific variables for Fedora or FreeBSD.] ****************************************************************************************** | + | TASK [geerlingguy.java : Include OS-specific variables for Fedora or FreeBSD.] *********************************************************************************************************************************** |
- | skipping: [web04] | + | |
skipping: [web01] | skipping: [web01] | ||
skipping: [web02] | skipping: [web02] | ||
skipping: [web03] | skipping: [web03] | ||
- | |||
- | TASK [geerlingguy.java : Include version-specific variables for CentOS/ | ||
skipping: [web04] | skipping: [web04] | ||
+ | |||
+ | TASK [geerlingguy.java : Include version-specific variables for CentOS/ | ||
skipping: [web01] | skipping: [web01] | ||
skipping: [web02] | skipping: [web02] | ||
skipping: [web03] | skipping: [web03] | ||
- | |||
- | TASK [geerlingguy.java : Include version-specific variables for Ubuntu.] ************************************************************************************************ | ||
skipping: [web04] | skipping: [web04] | ||
+ | |||
+ | TASK [geerlingguy.java : Include version-specific variables for Ubuntu.] ***************************************************************************************************************************************** | ||
skipping: [web01] | skipping: [web01] | ||
skipping: [web02] | skipping: [web02] | ||
skipping: [web03] | skipping: [web03] | ||
+ | skipping: [web04] | ||
- | TASK [geerlingguy.java : Include version-specific variables for Debian.] ************************************************************************************************ | + | TASK [geerlingguy.java : Include version-specific variables for Debian.] ***************************************************************************************************************************************** |
- | ok: [web04] | + | |
- | ok: [web01] | + | |
ok: [web02] | ok: [web02] | ||
ok: [web03] | ok: [web03] | ||
- | + | ok: [web01] | |
- | TASK [geerlingguy.java | + | |
ok: [web04] | ok: [web04] | ||
+ | |||
+ | TASK [geerlingguy.java : Define java_packages.] ****************************************************************************************************************************************************************** | ||
ok: [web01] | ok: [web01] | ||
ok: [web02] | ok: [web02] | ||
ok: [web03] | ok: [web03] | ||
+ | ok: [web04] | ||
- | TASK [geerlingguy.java : include_tasks] ********************************************************************************************************************************* | + | TASK [geerlingguy.java : include_tasks] ************************************************************************************************************************************************************************** |
- | skipping: [web04] | + | |
skipping: [web01] | skipping: [web01] | ||
skipping: [web02] | skipping: [web02] | ||
skipping: [web03] | skipping: [web03] | ||
+ | skipping: [web04] | ||
- | TASK [geerlingguy.java : include_tasks] ********************************************************************************************************************************* | + | TASK [geerlingguy.java : include_tasks] |
- | included: / | + | included: / |
- | TASK [geerlingguy.java : Ensure ' | + | TASK [geerlingguy.java : Ensure ' |
- | skipping: [web04] | + | |
skipping: [web01] | skipping: [web01] | ||
skipping: [web02] | skipping: [web02] | ||
skipping: [web03] | skipping: [web03] | ||
+ | skipping: [web04] | ||
- | TASK [geerlingguy.java : Ensure Java is installed.] ********************************************************************************************************************* | + | TASK [geerlingguy.java : Ensure Java is installed.] |
changed: [web04] | changed: [web04] | ||
changed: [web03] | changed: [web03] | ||
Ligne 1338: | Ligne 1271: | ||
changed: [web01] | changed: [web01] | ||
- | TASK [geerlingguy.java : include_tasks] ********************************************************************************************************************************* | + | TASK [geerlingguy.java : include_tasks] ************************************************************************************************************************************************************************** |
- | skipping: [web04] | + | |
skipping: [web01] | skipping: [web01] | ||
skipping: [web02] | skipping: [web02] | ||
skipping: [web03] | skipping: [web03] | ||
+ | skipping: [web04] | ||
- | TASK [geerlingguy.java : Set JAVA_HOME if configured.] ****************************************************************************************************************** | + | TASK [geerlingguy.java : Set JAVA_HOME if configured.] *********************************************************************************************************************************************************** |
- | skipping: [web04] | + | |
skipping: [web01] | skipping: [web01] | ||
skipping: [web02] | skipping: [web02] | ||
skipping: [web03] | skipping: [web03] | ||
+ | skipping: [web04] | ||
- | PLAY RECAP ************************************************************************************************************************************************************** | + | PLAY RECAP ******************************************************************************************************************************************************************************************************* |
- | web01 : ok=5 changed=1 | + | web01 : ok=5 changed=1 |
- | web02 : ok=5 changed=1 | + | web02 : ok=5 changed=1 |
- | web03 : ok=5 changed=1 | + | web03 : ok=5 changed=1 |
- | web04 : ok=5 changed=1 | + | web04 : ok=5 changed=1 |
</ | </ | ||
- | <WRAP center round important 60%> | + | Notez qu' |
- | **Important** : Notez qu' | + | |
- | </ | + | |
+ | < | ||
+ | [trainee@centos8 ~]$ ansible-config dump |grep ROLES_PATH | ||
+ | DEFAULT_ROLES_PATH(default) = ['/ | ||
+ | </ | ||
+ | |||
+ | Le PLAY RECAP contient 7 catégories : | ||
+ | |||
+ | * **ok** | ||
+ | * le nombre de tâches qui ont été traitées sans erreur | ||
+ | * **changed** | ||
+ | * le nombre de tâches qui ont effectué des modifications sur un des hôtes concernés | ||
+ | * **unreachable** | ||
+ | * le nombre de tâches qui n'ont pas été exécutées parce que l' | ||
+ | * **failed** | ||
+ | * le nombre de tâches en erreur pour lesquelles la valeur de **ignore_errors: | ||
+ | * **skipped** | ||
+ | * le nombre de tâches qui n'ont pas été exécutées parce que la valeur de la clause **when** était **fausse** | ||
+ | * **rescued** | ||
+ | * le nombre de tâches de type **rescue** qui ont été exécutées suite à une erreur ailleurs dans le playbook | ||
+ | * **ignored** | ||
+ | * le nombre de tâches en erreur pour lesquelles la valeur de **ignore_errors: | ||
+ | |||
+ | Pour mieux expliquer la catégorie **rescued**, | ||
+ | |||
+ | < | ||
+ | --- | ||
+ | - name: Ansible Blocks | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | - block: | ||
+ | - name: List home directory content | ||
+ | command: "ls -l ~/" | ||
+ | |||
+ | - name: Failing intentionally | ||
+ | command: "ls -l / | ||
+ | |||
+ | | ||
+ | - name: Rescue block (perform recovery) | ||
+ | debug: | ||
+ | msg: " | ||
+ | |||
+ | | ||
+ | - name: This will execute always | ||
+ | debug: | ||
+ | msg: "I will execute even in failure scenario" | ||
+ | </ | ||
+ | |||
+ | Dans le cas ci-dessus, la deuxième tâche dans la section **block** va générer une erreur. Dans ce cas la tâche dans la section **rescue** sera exécutée. Dans **tous** les cas la tâche dans la section **always** sera exécutée. | ||
----- | ----- | ||
- | < | + | |
- | <div align=" | + | Copyright © 2023 Hugh Norris. |
- | Copyright © 2020 Hugh NORRIS | + | |
- | </ | + | |
- | </ | + |