I would like to know if something has changed in order to do something.
Is there a global variable somewhere with the number of changed for the host?
More details: I am doing a lot of things on a system: modify system config, install new packages…
At the end, if something has changed for the host, I would like to rebuild the integrity database.
In my current configuration, the same host can be in different groups, with different roles.
So, if I add an handler, it can be executed several times, and I would have to add notify:… for a lot of tasks.
Thanks for your help.
The handler doesn’t run on each notification. It won’t do anything until the end of the play and should only run once, even if multiple tasks within the play have notified.
That does not work.
My machine is in several groups (one group for OS tasks, one for webservers tasks…)
For each group, I have different roles.
Even if I use the same handler (through include …/…/common/…) for two roles, the handler
is called twice for the same machine, one for the first group, one for the second.
In summary, I have several plays in my playbook, but the same host may appear in several plays.
My plays are for example: dbservers, core_os, webservers… And a host may be at the same time a dbserver and webserver,
so I will do the tasks for dbservers and webservers on the same host.
I would like to run a handler only once for a host. But it seems this is not possible: handler is run per play.
If I could get number of changes for a host, I could run a task for that host only if something has changed.
Else I have to re-organize my plays and have only one play per host…
Another solution is to use set_fact to set a flag: false at the beginning, and handler set it to true if modifications are done.
At the end, do the last action when flag is true.