# Notifying handlers only on items in loop that changed

**URL:** <https://forum.ansible.com/t/notifying-handlers-only-on-items-in-loop-that-changed/12308>\
**Category:** Ansible Project\
**Created:** [February 7, 2013, 9:28pm UTC](https://forum.ansible.com/t/notifying-handlers-only-on-items-in-loop-that-changed/12308 "2013-02-07T21:28:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Berman](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Andrew\_Berman](https://forum.ansible.com/u/Andrew_Berman)\
**Post date:** [February 7, 2013, 9:28pm UTC](https://forum.ansible.com/t/notifying-handlers-only-on-items-in-loop-that-changed/12308/1 "2013-02-07T21:28:14Z")

</div>

Hello,

I was wondering if it’s possible to do something like this scenario:

1. Create a bunch of users using a with\_items loop, then notify #2
2. Set the password on those users using the with\_items loop
3. Then at a later date, I add more users to the script and run again, but only change the password for those users that were not created.  
Thanks,

Andrew

---

<div class="post-metadata">

**Author:** ![Andrew\_Berman](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Andrew\_Berman](https://forum.ansible.com/u/Andrew_Berman)\
**Post date:** [February 8, 2013, 8:53pm UTC](https://forum.ansible.com/t/notifying-handlers-only-on-items-in-loop-that-changed/12308/2 "2013-02-08T20:53:03Z")

</div>

I did this a different way to accomplish it. I created an external task and included that task looping through each user. So like this:

External task (pseudo-yaml):

- user: name=$user …  
register: last\_result

- set\_password  
shell: passwd $user  
when\_changed: $last\_result

Then in the playbook:

- include myTask.yml $item  
with\_items:
- user1
- user2

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 8, 2013, 9:16pm UTC](https://forum.ansible.com/t/notifying-handlers-only-on-items-in-loop-that-changed/12308/3 "2013-02-08T21:16:33Z")

</div>

This is good!

We should put this on our Tips & Tricks page (which is sort of in  
early pull request territory)

---

<div class="post-metadata">

**Author:** ![Andrew\_Berman](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Andrew\_Berman](https://forum.ansible.com/u/Andrew_Berman)\
**Post date:** [February 8, 2013, 9:26pm UTC](https://forum.ansible.com/t/notifying-handlers-only-on-items-in-loop-that-changed/12308/4 "2013-02-08T21:26:42Z")

</div>

Sure, I’d be happy to submit something.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 9, 2013, 1:50am UTC](https://forum.ansible.com/t/notifying-handlers-only-on-items-in-loop-that-changed/12308/5 "2013-02-09T01:50:23Z")

</div>

We are trying to push this to [https://coderwall.com/p/t/ansible](https://coderwall.com/p/t/ansible) --  
feel free to contribute!
