tutorial.pdf: update to the latest template
This commit is contained in:
parent
23451ed479
commit
2788600d4f
10 changed files with 179 additions and 156 deletions
|
|
@ -87,11 +87,11 @@ Lancez ensuite la commande suivante :
|
|||
|
||||
<div lang="en-US">
|
||||
```
|
||||
42sh$ ansible --inventory-file hosts all --module-name ping --user root --ask-pass
|
||||
192.168.0.106 | SUCCESS => {
|
||||
"changed": false,
|
||||
"ping": "pong"
|
||||
}
|
||||
42sh$ ansible --inventory-file hosts all --module-name ping --user root --ask-pass
|
||||
192.168.0.106 | SUCCESS => {
|
||||
"changed": false,
|
||||
"ping": "pong"
|
||||
}
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -115,8 +115,8 @@ Et ajoutez les options `--become` et `--ask-become-pass` (utilisez `--sudo` et
|
|||
`--ask-sudo-pass` pour les vieilles versions) :
|
||||
|
||||
<div lang="en-US">
|
||||
```
|
||||
ansible --inventory-file hosts all -m ping -u bruce --become --ask-become-pass
|
||||
```bash
|
||||
ansible --inventory-file hosts all -m ping -u bruce --become --ask-become-pass
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -147,8 +147,8 @@ Parmi les modules de base, le module `setup` permet de récupérer un grand
|
|||
nombre de caractéristiques de la machine distance, voyez plutôt :
|
||||
|
||||
<div lang="en-US">
|
||||
```
|
||||
ansible -i hosts all -m setup
|
||||
```bash
|
||||
ansible -i hosts all -m setup
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -205,8 +205,8 @@ Placer le contenu dans un fichier YAML, par exemple `playbook.yml`, non loin du
|
|||
fichier `hosts` créé à la section précédentes, puis lancez :
|
||||
|
||||
<div lang="en-US">
|
||||
```
|
||||
ansible-playbook -i hosts playbook.yml
|
||||
```bash
|
||||
ansible-playbook -i hosts playbook.yml
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -256,10 +256,10 @@ Pour se faire, il faut ajouter un élément `notify` à sa tâche :
|
|||
|
||||
<div lang="en-US">
|
||||
```yaml
|
||||
- name: template configuration file
|
||||
template: src=template.j2 dest=/etc/httpd.conf
|
||||
notify:
|
||||
- restart cherokee
|
||||
- name: template configuration file
|
||||
template: src=template.j2 dest=/etc/httpd.conf
|
||||
notify:
|
||||
- restart cherokee
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -267,9 +267,9 @@ Puis, au même niveau que les *tasks*, on déclare nos *handlers* :
|
|||
|
||||
<div lang="en-US">
|
||||
```yaml
|
||||
handlers:
|
||||
- name: restart cherokee
|
||||
service: name=cherokee state=restarted
|
||||
handlers:
|
||||
- name: restart cherokee
|
||||
service: name=cherokee state=restarted
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -305,11 +305,11 @@ récupérée par un module (comme le module `setup`).
|
|||
|
||||
<div lang="en-US">
|
||||
```yaml
|
||||
all:
|
||||
hosts:
|
||||
192.168.0.106
|
||||
vars:
|
||||
ntp_server: ntp.epitech.eu
|
||||
all:
|
||||
hosts:
|
||||
192.168.0.106
|
||||
vars:
|
||||
ntp_server: ntp.epitech.eu
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -327,9 +327,9 @@ variables dans une recette :
|
|||
|
||||
<div lang="en-US">
|
||||
```yaml
|
||||
- hosts: webservers
|
||||
vars:
|
||||
http_port: 80
|
||||
- hosts: webservers
|
||||
vars:
|
||||
http_port: 80
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -337,9 +337,9 @@ Ces variables peuvent être placées dans un fichier, pour plus de lisibilité :
|
|||
|
||||
<div lang="en-US">
|
||||
```yaml
|
||||
- hosts: webservers
|
||||
vars_files:
|
||||
- /vars/webservers_common.yml
|
||||
- hosts: webservers
|
||||
vars_files:
|
||||
- /vars/webservers_common.yml
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -347,8 +347,8 @@ Le format correspond au sous arbre que l'on pourrait trouver sous `vars` :
|
|||
|
||||
<div lang="en-US">
|
||||
```yaml
|
||||
http_port: 80
|
||||
https_port: 443
|
||||
http_port: 80
|
||||
https_port: 443
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -363,8 +363,8 @@ template, un format très courant dans le milieu du développement Python.
|
|||
|
||||
<div lang="en-US">
|
||||
```
|
||||
I'm running {{ ansible_system }} {{ ansible_os_family }} on {{ ansible_system_vendor }},
|
||||
with {{ ansible_memory_mb.swap.free }} MB Swap available.
|
||||
I'm running {{ ansible_system }} {{ ansible_os_family }} on {{ ansible_system_vendor }},
|
||||
with {{ ansible_memory_mb.swap.free }} MB Swap available.
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -374,17 +374,21 @@ table de hash/dictionnaire, on utilise le caractère `.` ;
|
|||
Les crochets `[x]` sont utilisés principalement pour accéder aux éléments des
|
||||
tableaux :
|
||||
|
||||
<div lang="en-US">
|
||||
```
|
||||
My first nameserver is: {{ ansible_dns.nameservers[0] }}.
|
||||
My first nameserver is: {{ ansible_dns.nameservers[0] }}.
|
||||
```
|
||||
</div>
|
||||
|
||||
ou d'un dictionnaire lorsque la clef doit être récupérée d'une variable :
|
||||
|
||||
<div lang="en-US">
|
||||
```
|
||||
My disks are: {% for disk in ansible_device_links.uuids %}
|
||||
- {{ disk }}: {{ ansible_device_links.uuids[disk] }}, {{ ansible_device_links.ids[disk]|join(', ') }}
|
||||
{% endfor %}
|
||||
My disks are: {% for disk in ansible_device_links.uuids %}
|
||||
- {{ disk }}: {{ ansible_device_links.uuids[disk] }}, {{ ansible_device_links.ids[disk]|join(', ') }}
|
||||
{% endfor %}
|
||||
```
|
||||
</div>
|
||||
|
||||
Notez dans ce dernier exemple l'utilisation d'un filtre `join` permettant
|
||||
d'aplatir la liste retournée.
|
||||
|
|
@ -396,10 +400,10 @@ Jinja2 :
|
|||
|
||||
<div lang="en-US">
|
||||
```yaml
|
||||
- hosts: webservers
|
||||
vars_files:
|
||||
- /vars/webservers_common.yml
|
||||
- /vars/webservers_{{ ansible_os_family }}.yml
|
||||
- hosts: webservers
|
||||
vars_files:
|
||||
- /vars/webservers_common.yml
|
||||
- /vars/webservers_{{ ansible_os_family }}.yml
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
@ -414,13 +418,13 @@ tâches. Par exemple :
|
|||
|
||||
<div lang="en-US">
|
||||
```yaml
|
||||
tasks:
|
||||
- name: "pkg setup (Debian)"
|
||||
apt: name=chrony state=present
|
||||
when: ansible_os_family == "Debian"
|
||||
- name: "pkg setup (CentOS)"
|
||||
yum: name=chrony state=present
|
||||
when: ansible_os_family == "CentOS"
|
||||
tasks:
|
||||
- name: "pkg setup (Debian)"
|
||||
apt: name=chrony state=present
|
||||
when: ansible_os_family == "Debian"
|
||||
- name: "pkg setup (CentOS)"
|
||||
yum: name=chrony state=present
|
||||
when: ansible_os_family == "CentOS"
|
||||
```
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Reference in a new issue