26 lines
1.1 KiB
Markdown
26 lines
1.1 KiB
Markdown
|
# 11 - Conditionals
|
||
|
|
||
|
This exercise makes you write a playbooks with tasks that are run when specific condition is met.
|
||
|
|
||
|
## Playbook Creation
|
||
|
|
||
|
Write a playbook following the given specs:
|
||
|
* Run on host group `lab`
|
||
|
* Reboot the server if the uptime is more than 600 seconds
|
||
|
* Wait for the server to reboot
|
||
|
* Print a message stating that "Host <host> has been rebooted" (only if it has been rebooted)
|
||
|
|
||
|
## Hints and Caveats
|
||
|
* If you just run the reboot command, Ansible will fail because the connection will be lost with the managed host.
|
||
|
* You must use the `poll` and `async` task settings to run the reboot task asynchronously.
|
||
|
* There is a `wait_for_connection` module that may be useful.
|
||
|
* You need the reboot task to be run even if Ansible close the session and you need to give some time to Ansible to perform its operation before the actual reboot. For this run it like this:
|
||
|
```bash
|
||
|
nohup sh -c '(sleep 5 ; reboot)'
|
||
|
```
|
||
|
* Because of [this bug](https://github.com/ansible/ansible/issues/37941), asynchronous tasks seems to be failing with Python 3. Use Python2 instead.
|
||
|
|
||
|
## Validation
|
||
|
|
||
|
There is a working playbook in `solution/solution.yml`.
|