Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bonnegent Sebastien
Cours Ansible
Commits
e5f57f3e
Commit
e5f57f3e
authored
Nov 24, 2020
by
Bonnegent Sebastien
Browse files
correction des coquilles :)
parent
ccb7bafc
Pipeline
#8667
passed with stage
in 15 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
e5f57f3e
*~
html/*.html
html/images/
Makefile
View file @
e5f57f3e
...
...
@@ -10,7 +10,7 @@ help:
html/%.html
:
%.md
@
test
!
-e
html/images
&&
mkdir
html/images
@
cp
images/
*
html/images/
pandoc
-s
-t
revealjs
-V
revealjs-url
=
./reveal.js-3.9.2
-V
theme
=
league
-o
$@
$<
@
pandoc
-s
-t
revealjs
-V
revealjs-url
=
./reveal.js-3.9.2
-V
theme
=
league
-o
$@
$<
%.pdf
:
%.md
pandoc
-t
beamer
$<
-V
theme:Madrid
-o
$@
...
...
cours1.md
View file @
e5f57f3e
...
...
@@ -10,8 +10,8 @@ title: Ansible Pratique
*
version html:
<https://gitlab.insa-rouen.fr/bonnegent/cours_ansible/-/pipelines>
## A quoi ca sert ?
-
automatisation des installation
-
automatisation des configuration
-
automatisation des installation
s
-
automatisation des configuration
s
-
validation
=> quelque soit le nombre de cibles !
...
...
@@ -242,32 +242,41 @@ root@d743d4e1dd28:~# echo "relancer le playbook"
## Boucles
~~~
yml
-
name: installation de plusieurs paquets
apt:
name: {{ item }}
state: present
with_items:
-
vim
-
netcat
-
htop
---
-
name
:
mon playbook
hosts
:
ubuntu
tasks
:
-
name
:
installation de plusieurs paquets
apt
:
name
:
{{
item
}}
state
:
present
with_items
:
-
vim
-
netcat
-
htop
~~~
## Boucles pour les installations
~~~yml
-
name: installation de plusieurs paquets
apt:
name: ['vim', 'netcat', 'htop']
state: present
---
-
name: mon playbook
hosts: ubuntu
tasks:
-
name: installation de plusieurs paquets
apt:
name: ['vim', 'netcat', 'htop']
state: present
~~~
## Cron
~~~
yml
-
name:
auto renew des certificats
-
name:
cron de sauvegarde
cron:
name: letsencrypt_renewal
name: sauvegarde
user: postgres
special_time: monthly
job: "
/usr/bin/certbot renew
"
job: "
pg_dumpall > /var/lib/pgsql/backups/dumpall.sql
"
-
name: mise à jour automatique base antivirus
cron:
...
...
@@ -284,13 +293,17 @@ $ date > files/test_copie.txt
~~~
~~~
yml
-
name: copie d'un fichier
copy:
src: test_copie.txt
dest: /root/
owner: root
group: root
mode: 0640
---
-
name
:
mon playbook
hosts
:
ubuntu
tasks
:
-
name
:
copie d'un fichier
copy
:
src
:
test_copie.txt
dest
:
/root/
owner
:
root
group
:
root
mode
:
0640
~~~
## Template
...
...
@@ -301,14 +314,19 @@ ansible_hostname: {{ ansible_hostname }}
~~~
~~~yml
-
name: copie d'un template
template:
src: test_template.txt
dest: /root/
---
-
name: mon playbook
hosts: ubuntu
tasks:
-
name: copie d'un template
template:
src: test_template.txt
dest: /root/
~~~
## Mise à jour
~~~
yml
---
-
name: Mise à jour des paquets
hosts: all
tasks:
...
...
@@ -327,8 +345,10 @@ ansible_hostname: {{ ansible_hostname }}
## Variables
~~~
bash
$ mkdir group_vars host_vars
$ echo "une variable: {{ test_var }}" >> templates/test_template.txt
$ echo "une variable: {{ test_var }}"
\
>> templates/test_template.txt
$ echo "test_var: dans group_vars/all" >> group_vars/all
$
$ ansible-playbook -i hosts template.yml
$ ansible all -i ./hosts -a "cat /root/test_template.txt"
~~~
...
...
@@ -357,7 +377,14 @@ $ echo "test_var: dans host_vars" >> host_vars/cible1
$ mv host_vars/cible1 vars.yml
$ mkdir host_vars/cible1
$ mv vars.yml host_vars/cible1/
$ echo 'mon_secret: "{{ vault_mon_secret }}"' >> host_vars/cible1/vars.yml
$ echo 'mon_secret: "{{ vault_mon_secret }}"'
\
>> host_vars/cible1/vars.yml
~~~
### host_vars/cible1/vault.yml
~~~
vault_mon_secret: UnSuperMotDePasse
vault_truc: un autre
~~~
## Creation du trousseau
...
...
@@ -371,7 +398,8 @@ $ ansible-playbook -i hosts template.yml
PLAY [template]
********
ERROR! Attempting to decrypt but no vault secrets found
$ ansible-playbook -i hosts --ask-vault-pass template.yml
$ ansible-playbook -i hosts --vault-password-file .vault_pass_file template.yml
$ ansible-playbook -i hosts --vault-password-file
\
.vault_pass_file template.yml
~~~
# Handler
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment