Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| df32926ad2 | |||
| f5669f671d | |||
| 07eb50aeea | |||
| d8f1b79189 | |||
| da43eabcbe | |||
| 312335742f | |||
| 072a555f21 | |||
| 33c48d2b74 | |||
| d3dd99b100 |
13
Readme.md
13
Readme.md
@@ -1,13 +0,0 @@
|
|||||||
## Les handlers
|
|
||||||
|
|
||||||
**Tâche**: Relancer un service uniquement en cas de modification de la configuration
|
|
||||||
|
|
||||||
**Condition**: déploiement d'un service
|
|
||||||
|
|
||||||
**Norme**: handler
|
|
||||||
|
|
||||||
**Pratique**: Modifiez le playbook apache.yml afin que le déploiement d'une nouvelle version du fichier vhost.conf entraîne un redémarrage du service apache.
|
|
||||||
|
|
||||||
Solution: voir branche "solution"
|
|
||||||
|
|
||||||
Pratique bis: utiliser le module _ansible.builtin.meta_ afin de forcer l'exécution du handler (si besoin) juste après la tâche "conf httpd"
|
|
||||||
29
apache.yml
29
apache.yml
@@ -1,42 +1,51 @@
|
|||||||
---
|
---
|
||||||
- name: install apache via ansible playbook
|
- name: install apache via ansible playbook
|
||||||
hosts: centos
|
hosts: centos
|
||||||
|
handlers:
|
||||||
|
- name: restart apache
|
||||||
|
service:
|
||||||
|
name: httpd
|
||||||
|
state: restarted
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: install apache
|
- name: install apache
|
||||||
yum:
|
ansible.builtin.package:
|
||||||
name: httpd
|
name: httpd
|
||||||
state: present
|
state: latest
|
||||||
|
|
||||||
- name: conf httpd
|
- name: conf httpd
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: vhost.conf
|
src: vhost.conf
|
||||||
dest: /etc/httpd/conf.d/vhost.conf
|
dest: /etc/httpd/conf.d/vhost.conf
|
||||||
mode: 0640
|
mode: 0640
|
||||||
owner: root
|
owner: root
|
||||||
group: apache
|
group: apache
|
||||||
|
notify: restart apache
|
||||||
|
|
||||||
|
- name: call handlers, if needed
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
|
|
||||||
- name: activate apache
|
- name: activate apache
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: httpd
|
name: httpd
|
||||||
enabled: yes
|
enabled: yes
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: open firewall port
|
- name: open firewall port
|
||||||
firewalld:
|
ansible.posix.firewalld:
|
||||||
service: http
|
service: http
|
||||||
permanent: yes
|
permanent: yes
|
||||||
immediate: yes
|
immediate: yes
|
||||||
state: enabled
|
state: enabled
|
||||||
ignore_errors: true
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: create documentroot
|
- name: create documentroot
|
||||||
file:
|
ansible.builtin.file:
|
||||||
name: /var/www/html/example.org/
|
name: /var/www/html/example.org
|
||||||
state: directory
|
state: directory
|
||||||
|
|
||||||
- name: copy index file
|
- name: create index file
|
||||||
template:
|
ansible.builtin.copy:
|
||||||
src: index.txt
|
src: index.txt
|
||||||
dest: /var/www/html/example.org/index.html
|
dest: /var/www/html/example.org/index.html
|
||||||
mode: 0644
|
mode: 0644
|
||||||
Reference in New Issue
Block a user