5.1 Ansible Roles - Handlers and Blocks
We start to use handlers and blocks as well.
- Create a playbook
myhandler.ymlwhich applies a role
- The role
handlerroleshould do the following:
- Create a directory
newdirin the folder
- If the folder didn’t exist before, then do create a file
README.TXTin this folder containing the text “This folder was created at
- The value of
<timestamp>should contain a quite accurate timestamp of when
- Run the playbook several times to see if it is really idempotent.
Solution Task 1
Below is a possible solution:
- Write a playbook
download.ymlwhich runs a role
- The role
downloadershould try to download a file from a non-existing URL.
- The role should be able to handle errors. Let it write the message “Download failed!” to standard output if the download task failed. The playbook must keep on running and shall not exit after this message.
- In all cases, output a message at the end of the play informing that the download attempt has finished.
- Use a
block:to do these tasks.
- Run the playbook
Solution Task 2
Note the failed download task, but the playbook finished nonetheless.
Last modified November 20, 2023: Merge pull request #216 from puzzle/psc_edaserver_lab (d791dbe)