From 1781faeb4e094380e3d3677309450fd95bb5292a Mon Sep 17 00:00:00 2001 From: Gregory Colpart Date: Fri, 28 Jul 2023 17:39:01 +0200 Subject: [PATCH] =?UTF-8?q?relecture=20du=20d=C3=A9but=20du=20Howto=20Ansi?= =?UTF-8?q?ble?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HowtoAnsible.md | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/HowtoAnsible.md b/HowtoAnsible.md index 3963294b..715e080c 100644 --- a/HowtoAnsible.md +++ b/HowtoAnsible.md @@ -1,6 +1,6 @@ --- categories: automation -title: Howto Ansible : automatisation d'infrastructure +title: Howto Ansible ... * Documentation : @@ -20,7 +20,13 @@ Nous utilisons actuellement Ansible 2.10 (version proposée en Debian 11) : # apt install ansible sshpass $ ansible --version +/usr/lib/python3/dist-packages/paramiko/transport.py:219: CryptographyDeprecationWarning: Blowfish has been deprecated + "class": algorithms.Blowfish, ansible 2.10.8 + config file = /home/gcolpart/.ansible.cfg + configured module search path = ['/home/gcolpart/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] + ansible python module location = /usr/lib/python3/dist-packages/ansible + executable location = /usr/bin/ansible python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] ~~~ @@ -64,20 +70,27 @@ localhost | SUCCESS => { } ~~~ -Ou sur une machine distante : +Ou sur une machine distante avec l'IP 192.0.2.42 : ~~~ -$ echo mon-serveur >> ~/.ansible/hosts $ ssh-copy-id mon-serveur -$ ansible mon-serveur -i $HOME/.ansible/hosts -m ansible.builtin.ping --one-line --forks 1 +$ ansible mon-serveur -i 192.0.2.42, -m ansible.builtin.ping --one-line --forks 1 mon-serveur | SUCCESS => {"changed": false, "ping": "pong"} +~~~ -$ ansible "mon-*" -m ansible.builtin.command --args "date" -mon-serveur | SUCCESS | rc=0 >> +Ou sur plusieurs machines distantes présentes dans un inventaire : + +~~~ +$ echo mon-serveur1 >> ~/.ansible/hosts +$ echo mon-serveur2 >> ~/.ansible/hosts +$ ansible "mon-*" -i $HOME/.ansible/hosts -m ansible.builtin.command --args "date" +mon-serveur1 | SUCCESS | rc=0 >> +jeudi 26 mai 2016, 23:16:01 (UTC+0200) +mon-serveur2 | SUCCESS | rc=0 >> jeudi 26 mai 2016, 23:16:01 (UTC+0200) ~~~ -Par exemple, pour lister les serveurs qui ont le packet `lxc` installé : +Par exemple, pour lister les serveurs qui ont le package `lxc` installé : ~~~ $ ansible stretch,buster,bullseye -bK --one-line --forks 42 -m ansible.builtin.shell --args 'dpkg -l | grep lxc | grep -q ii' | grep CHANGED