Home > Ansible > Considerations on Ansible handlers

Considerations on Ansible handlers

1) Handlers should go at the bottom of the PLAY
https://docs.ansible.com/playbooks_roles.html
“And in your main playbook file, just include it like so, at the bottom of a play:”

But I have seen that if you declare it even at the beginning, it works anyway.

2) You can call handlers/*.yml whatever you want, it doesn’t have to be necessarily main.yml

3) In notify you can use

[cce_yaml]notify: mysql_restart[/cce]

or

[cce_yaml]notify:
- mysql_restart[/cce]

both will work

4) If the handler is defined inside the PLAY, you can call it even from an included task

5) A handler will always be called at the end of the play.
If you need to run it when you notify it, you need to add

[cce_yaml]- meta: flush_handlers[/cce]

http://wherenow.org/ansible-handlers/

6) Calling the handler multiple times will result in only one run.

https://docs.ansible.com/playbooks_intro.html
“These ‘notify’ actions are triggered at the end of each block of tasks in a playbook, and will only be triggered once even if notified by multiple different tasks.”

Categories: Ansible Tags: , multiple
  1. No comments yet.
  1. No trackbacks yet.