Is it possible to know if something has changed?

61 views
Skip to first unread message

Olivier Javaux

unread,
Sep 18, 2014, 11:47:51 AM9/18/14
to ansible...@googlegroups.com
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.

Mark McCoy

unread,
Sep 18, 2014, 3:13:31 PM9/18/14
to ansible-project
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/088cf9c9-4afc-4984-a203-d1270ede5838%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Olivier Javaux

unread,
Sep 20, 2014, 4:24:09 AM9/20/14
to ansible...@googlegroups.com
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.


Olivier Javaux

unread,
Sep 20, 2014, 5:08:37 AM9/20/14
to ansible...@googlegroups.com
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...

Olivier Javaux

unread,
Sep 20, 2014, 5:25:44 AM9/20/14
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Sep 21, 2014, 3:35:23 PM9/21/14
to ansible...@googlegroups.com
"is called twice for the same machine, one for the first group, one for the second."


This is not the case actually, but handlers are notified on a play by play basis.



On Sat, Sep 20, 2014 at 5:25 AM, Olivier Javaux <olivier...@orange.fr> wrote:
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages