Skip to content
Snippets Groups Projects
Commit e11ba24d authored by Vincent Mazenod's avatar Vincent Mazenod
Browse files

ansible

parent b967e73c
No related branches found
No related tags found
No related merge requests found
Pipeline #3389 passed
...@@ -13,20 +13,21 @@ ...@@ -13,20 +13,21 @@
* racheté par RedHat en octobre 2015 * racheté par RedHat en octobre 2015
* outils équivalents * outils équivalents
* puppet, chief, salt ... * [puppet](https://puppet.com/), [chef](https://www.chef.io/#/), [SaltStack](https://www.saltstack.com/) ...
## ansible Φ ## ansible Φ
* idempotence * automatisation
* héritage
* réutilisabilité * réutilisabilité
* parallélisation * parallélisation
* automatisation * idempotence
<br />
#### toute intervention manuelle sur un système est une faute ... #### toute intervention manuelle sur un système est une faute ...<!-- .element class="fragment" -->
## ... GRAVE! ## ... GRAVE!<!-- .element class="fragment" -->
## ansible ## ansible
...@@ -36,7 +37,7 @@ ...@@ -36,7 +37,7 @@
* marche bien en python 3 <3 * marche bien en python 3 <3
* virtualenv * virtualenv
* [<i class="fa fa-book" aria-hidden="true"></i> ansible](https://docs.ansible.com/) [<i class="fa fa-book" aria-hidden="true"></i> ansible doc](https://docs.ansible.com/)
## ansible ## ansible
...@@ -79,37 +80,42 @@ ...@@ -79,37 +80,42 @@
## terminologie ## terminologie
* **play**
* est l'exécution d'un playbook sur une machine
* **facts** * **facts**
* information collectée par ansible sur le système d'une machine à configurer * information collectée par ansible sur le système d'une machine à configurer
* peuvent être enrichis
* **handlers** * **handlers**
* similaire aux **tasks** mais appelable à partir d'une **task** * similaire aux **tasks** mais appelables à partir d'une **task**
* redémarrage de service par exemple * typiquement redémarrage de service par exemple
## inventory ## inventory
* liste des machines accessibles en ssh
* organisées par groupes
* possibilité de fixer des configurations
* pour tous / par groupe / par machine
* possibilité de déclarer des variables
* pour tous / par groupe / par machine
* fichier texte au format *ini* * fichier texte au format *ini*
* organiser par groupes
* fixer des configurations
* pour tous / par groupe / par machine
* déclarer des variables
* pour tous / par groupe / par machine
[<i class="fa fa-book" aria-hidden="true"></i> inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html)
## inventory
* [<i class="fa fa-book" aria-hidden="true"></i> inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html) ## inventory
```ini ```ini
[other]
other1.isima.fr
[criprod] [criprod]
pvecriprod2.isima.fr pvecriprod2.isima.fr
py.criprod.isima.fr py.criprod.isima.fr
gitlab-runner1.criprod.isima.fr gitlab-runner1.criprod.isima.fr
[all:vars] [criprod:vars]
environment = production environment = production
[all:vars]
ansible_python_interpreter = /usr/bin/python3 ansible_python_interpreter = /usr/bin/python3
ansible_user = limosadm ansible_user = limosadm
``` ```
...@@ -130,12 +136,38 @@ Host py.criprod.isima.fr ...@@ -130,12 +136,38 @@ Host py.criprod.isima.fr
ProxyCommand ssh pvecriprod2.isima.fr -W %h:%p ProxyCommand ssh pvecriprod2.isima.fr -W %h:%p
``` ```
**N.B.** les machines de l'inventaire doivent être accessible en ssh à parti de la machine pilote
## ad-hoc command ## ad-hoc command
``` ```
$ ansible all --inventory-file=inventory.ini --module-name ping $ ansible criprod -a "/usr/bin/uptime"
other1.isima.fr | CHANGED | rc=0 >>
13:12:02 up 21 days, 21:11, 2 users, load average: 0.13, 0.88, 0.13
pvecriprod2.isima.fr | CHANGED | rc=0 >>
16:18:08 up 41 days, 23:11, 3 users, load average: 0.63, 0.18, 0.10
py.criprod.isima.fr | CHANGED | rc=0 >>
15:18:15 up 1 day, 21:51, 1 user, load average: 0.13, 0.03, 0.01
gitlab-runner1.criprod.isima.fr | CHANGED | rc=0 >>
15:18:15 up 1 day, 22:14, 1 user, load average: 0.00, 0.00, 0.00
```
## ad-hoc command
```shell
$ ansible all --inventory-file=inventory.ini \
--module-name ping
other1.isima.fr | SUCCESS => {
"changed": false,
"ping": "pong"
}
pvecriprod2.isima.fr | SUCCESS => { pvecriprod2.isima.fr | SUCCESS => {
"changed": false, "changed": false,
"ping": "pong" "ping": "pong"
...@@ -151,22 +183,6 @@ gitlab-runner1.criprod.isima.fr | SUCCESS => { ...@@ -151,22 +183,6 @@ gitlab-runner1.criprod.isima.fr | SUCCESS => {
``` ```
## ad-hoc command
```
$ ansible criprod -a "/usr/bin/uptime"
pvecriprod2.isima.fr | CHANGED | rc=0 >>
16:18:08 up 41 days, 23:11, 3 users, load average: 0.63, 0.18, 0.10
py.criprod.isima.fr | CHANGED | rc=0 >>
15:18:15 up 1 day, 21:51, 1 user, load average: 0.13, 0.03, 0.01
gitlab-runner1.criprod.isima.fr | CHANGED | rc=0 >>
15:18:15 up 1 day, 22:14, 1 user, load average: 0.00, 0.00, 0.00
```
## ad-hoc command ## ad-hoc command
* [<i class="fa fa-book" aria-hidden="true"></i> ad-hoc command](https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html) * [<i class="fa fa-book" aria-hidden="true"></i> ad-hoc command](https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html)
...@@ -211,7 +227,9 @@ my-playbook.yml ...@@ -211,7 +227,9 @@ my-playbook.yml
$ ansible-playbook my-playbook.yml $ ansible-playbook my-playbook.yml
``` ```
exécute le playbook sur toutes les machines de l'inventaire * exécute le playbook
* sur toutes les machines définies dans hosts
* en parallèle
## playbook ## playbook
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment