Fourth exercise: using handlers
This commit is contained in:
parent
6994544f4d
commit
60ed86b31c
7 changed files with 54 additions and 0 deletions
14
40.Handlers/40.Handlers.md
Normal file
14
40.Handlers/40.Handlers.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
#40 - Handlers
|
||||
|
||||
This exercise makes you use handlers to control flow execution.
|
||||
|
||||
## Playbook creation
|
||||
Write a playbook following the given specs:
|
||||
* Run on host group `lab`
|
||||
* Install a web server (eg. `nginx` or `httpd`) on each host using the module adapted to the package manager of your hosts
|
||||
* Trigger a handler that starts the corresponding service (using appropriate module as well)
|
||||
|
||||
## Validation
|
||||
Run the playbook and checks if the service is installed and started.
|
||||
|
||||
There is a working playbook in `solution/solution.yml` (for an Alpine host)
|
7
40.Handlers/solution/cleanup.yml
Normal file
7
40.Handlers/solution/cleanup.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
- hosts: lab
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- include_tasks: tasks/stop_nginx.yml
|
||||
- include_tasks: tasks/uninstall_nginx.yml
|
||||
|
||||
# vim: set ft=yaml sw=2 et:
|
8
40.Handlers/solution/solution.yml
Normal file
8
40.Handlers/solution/solution.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
- hosts: lab
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- include_tasks: tasks/install_nginx.yml
|
||||
handlers:
|
||||
- import_tasks: tasks/restart_nginx.yml
|
||||
|
||||
# vim: set ft=yaml sw=2 et:
|
7
40.Handlers/solution/tasks/install_nginx.yml
Normal file
7
40.Handlers/solution/tasks/install_nginx.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
- name: Ensure nginx is installed
|
||||
become: true
|
||||
apk:
|
||||
name: nginx
|
||||
state: present
|
||||
notify: Restart Nginx
|
||||
# vim: set ft=yaml sw=2 et:
|
6
40.Handlers/solution/tasks/restart_nginx.yml
Normal file
6
40.Handlers/solution/tasks/restart_nginx.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
- name: Restart Nginx
|
||||
become: true
|
||||
sysvinit:
|
||||
name: nginx
|
||||
state: started
|
||||
# vim: set ft=yaml sw=2 et:
|
6
40.Handlers/solution/tasks/stop_nginx.yml
Normal file
6
40.Handlers/solution/tasks/stop_nginx.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
- name: Stop Nginx
|
||||
become: true
|
||||
sysvinit:
|
||||
name: nginx
|
||||
state: stopped
|
||||
# vim: set ft=yaml sw=2 et:
|
6
40.Handlers/solution/tasks/uninstall_nginx.yml
Normal file
6
40.Handlers/solution/tasks/uninstall_nginx.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
- name: Ensure nginx is uninstalled
|
||||
become: true
|
||||
apk:
|
||||
name: nginx
|
||||
state: absent
|
||||
# vim: set ft=yaml sw=2 et:
|
Loading…
Reference in a new issue