Fourth exercise: using handlers
This commit is contained in:
parent
6994544f4d
commit
60ed86b31c
|
@ -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)
|
|
@ -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:
|
|
@ -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:
|
|
@ -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:
|
|
@ -0,0 +1,6 @@
|
|||
- name: Restart Nginx
|
||||
become: true
|
||||
sysvinit:
|
||||
name: nginx
|
||||
state: started
|
||||
# vim: set ft=yaml sw=2 et:
|
|
@ -0,0 +1,6 @@
|
|||
- name: Stop Nginx
|
||||
become: true
|
||||
sysvinit:
|
||||
name: nginx
|
||||
state: stopped
|
||||
# vim: set ft=yaml sw=2 et:
|
|
@ -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 New Issue