# Is it possible to know if something has changed?

**URL:** <https://forum.ansible.com/t/is-it-possible-to-know-if-something-has-changed/16276>\
**Category:** Ansible Project\
**Created:** [September 18, 2014, 3:47pm UTC](https://forum.ansible.com/t/is-it-possible-to-know-if-something-has-changed/16276 "2014-09-18T15:47:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivier\_Javaux](https://avatars.discourse-cdn.com/v4/letter/o/3da27b/32.png) [@Olivier\_Javaux](https://forum.ansible.com/u/Olivier_Javaux)\
**Post date:** [September 18, 2014, 3:47pm UTC](https://forum.ansible.com/t/is-it-possible-to-know-if-something-has-changed/16276/1 "2014-09-18T15:47:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mark\_McCoy](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@Mark\_McCoy](https://forum.ansible.com/u/Mark_McCoy)\
**Post date:** [September 18, 2014, 7:13pm UTC](https://forum.ansible.com/t/is-it-possible-to-know-if-something-has-changed/16276/2 "2014-09-18T19:13:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Olivier\_Javaux](https://avatars.discourse-cdn.com/v4/letter/o/3da27b/32.png) [@Olivier\_Javaux](https://forum.ansible.com/u/Olivier_Javaux)\
**Post date:** [September 20, 2014, 8:24am UTC](https://forum.ansible.com/t/is-it-possible-to-know-if-something-has-changed/16276/3 "2014-09-20T08:24:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Olivier\_Javaux](https://avatars.discourse-cdn.com/v4/letter/o/3da27b/32.png) [@Olivier\_Javaux](https://forum.ansible.com/u/Olivier_Javaux)\
**Post date:** [September 20, 2014, 9:08am UTC](https://forum.ansible.com/t/is-it-possible-to-know-if-something-has-changed/16276/4 "2014-09-20T09:08:37Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Olivier\_Javaux](https://avatars.discourse-cdn.com/v4/letter/o/3da27b/32.png) [@Olivier\_Javaux](https://forum.ansible.com/u/Olivier_Javaux)\
**Post date:** [September 20, 2014, 9:25am UTC](https://forum.ansible.com/t/is-it-possible-to-know-if-something-has-changed/16276/5 "2014-09-20T09:25:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 21, 2014, 7:35pm UTC](https://forum.ansible.com/t/is-it-possible-to-know-if-something-has-changed/16276/6 "2014-09-21T19:35:18Z")

</div>

“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.
