# Conditional task using when\_changed

**URL:** <https://forum.ansible.com/t/conditional-task-using-when-changed/13611>\
**Category:** Ansible Project\
**Created:** [October 4, 2013, 4:41pm UTC](https://forum.ansible.com/t/conditional-task-using-when-changed/13611 "2013-10-04T16:41:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Chappell](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jon\_Chappell](https://forum.ansible.com/u/Jon_Chappell)\
**Post date:** [October 4, 2013, 4:41pm UTC](https://forum.ansible.com/t/conditional-task-using-when-changed/13611/1 "2013-10-04T16:41:44Z")

</div>

Greetings,

I’m running into unexpected behavior when trying to use a when\_changed statement to trigger an immediate service reload if a change is made. We wanted to do this instead of doing a flush\_handlers to avoid impacting the timing handlers that were triggered by other plays.

The following set of tasks in a role:

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [October 4, 2013, 5:46pm UTC](https://forum.ansible.com/t/conditional-task-using-when-changed/13611/2 "2013-10-04T17:46:56Z")

</div>

Does this happen if you use the new syntax of “when: result.changed”?

---

<div class="post-metadata">

**Author:** ![Jon\_Chappell](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jon\_Chappell](https://forum.ansible.com/u/Jon_Chappell)\
**Post date:** [October 4, 2013, 6:13pm UTC](https://forum.ansible.com/t/conditional-task-using-when-changed/13611/3 "2013-10-04T18:13:04Z")

</div>

Looks like it works with the new syntax. I didn’t even see a mention to that in the docs. Must have slipped by me.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 4, 2013, 6:41pm UTC](https://forum.ansible.com/t/conditional-task-using-when-changed/13611/4 "2013-10-04T18:41:50Z")

</div>

So BTW, this is wrong:

when\_changed: $result

Do this:

when\_changed: result

You only need to say “{{ foo }}” when you are forcing getting a string somewhere, and should never be using old style variables.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 4, 2013, 6:43pm UTC](https://forum.ansible.com/t/conditional-task-using-when-changed/13611/5 "2013-10-04T18:43:13Z")

</div>

Also, a bit confused here by the topic.

“changed\_when” is a thing that controls when something reports changed or not.

“when” is something that decides if something executes or not

“when: foo.changed” is a thing

you can also say

“when: foo|changed” and this better works with tasks that might be skipped, etc, and doesn’t require them to have a “.changed” attribute.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 4, 2013, 6:43pm UTC](https://forum.ansible.com/t/conditional-task-using-when-changed/13611/6 "2013-10-04T18:43:27Z")

</div>

There is no “when\_changed” 🙂
