relecture du début du Howto Ansible

This commit is contained in:
Gregory Colpart 2023-07-28 17:39:01 +02:00
parent 781d8309fb
commit 1781faeb4e

View file

@ -1,6 +1,6 @@
---
categories: automation
title: Howto Ansible : automatisation d'infrastructure
title: Howto Ansible
...
* Documentation : <http://docs.ansible.com/>
@ -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