# changed\_when in a loop gets lost

**URL:** <https://forum.ansible.com/t/changed-when-in-a-loop-gets-lost/30574>\
**Category:** Ansible Project\
**Created:** [June 14, 2019, 8:02pm UTC](https://forum.ansible.com/t/changed-when-in-a-loop-gets-lost/30574 "2019-06-14T20:02:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Matz1](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@Guy\_Matz1](https://forum.ansible.com/u/Guy_Matz1)\
**Post date:** [June 14, 2019, 8:02pm UTC](https://forum.ansible.com/t/changed-when-in-a-loop-gets-lost/30574/1 "2019-06-14T20:02:07Z")

</div>

Anyone know why the changed\_when is not reflected in the output initially? Only in the summary?

Here’s the code:

- name: disk space check  
debug:  
msg: “{{ item.mount }} failed check for {{ item.block\_available \* 4/1024000 }} free GB (Needed {{ pre\_check\_filesystems[item.mount] }})”  
when: item.mount in pre\_check\_filesystems  
changed\_when: item.block\_available \* 4/1024000|float \< pre\_check\_filesystems[item.mount]|float  
with\_items:
- "{{ ansible\_mounts }}

And the output (abbreviated for readabvlity):  
PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [mhg-desk-l09]

TASK [spacewalk/pre-check : disk space check - WARNINGS ON THIS ARE UNRELIABLE!!!] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
**ok:** [mhg-desk-l09] =\> (item={‘block\_used’: 869141, ‘uuid’: ‘1e7b178b-2bf2-4940-a912-8974e5fc07d6’, ‘size\_total’: 10475274240, ‘block\_total’: 2557440, ‘mount’: ‘/var’, ‘block\_available’: 1688299, ‘size\_available’: 6915272704, ‘fstype’: ‘xfs’, ‘inode\_total’: 5120000, ‘options’: ‘rw,relatime,attr2,inode64,noquota’, ‘device’: ‘/dev/sda5’, ‘inode\_used’: 15912, ‘block\_size’: 4096, ‘inode\_available’: 5104088}) =\> {  
“msg”: “**/var failed check for 6.59491796875 free GB (Needed 2)**”  
}  
ok: [mhg-desk-l09] =\> (item={‘block\_used’: 2227072, ‘uuid’: ‘17a5e1ee-6285-450a-b9f0-d923fda6ecb4’, ‘size\_total’: 10475274240, ‘block\_total’: 2557440, ‘mount’: ‘/usr’, ‘block\_available’: 330368, ‘size\_available’: 1353187328, ‘fstype’: ‘xfs’, ‘inode\_total’: 2948608, ‘options’: ‘rw,relatime,attr2,inode64,noquota’, ‘device’: ‘/dev/sda3’, ‘inode\_used’: 305619, ‘block\_size’: 4096, ‘inode\_available’: 2642989}) =\> {  
“msg”: “/usr failed check for 1.2905 free GB (Needed 2)”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
mhg-desk-l09 : **ok=2 changed=1** unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

So one of those checks should trigger a “changed” - and it does in the summary, but not in the body of the output. Another thing I just noticed . . . there were 2 tasks, one was ok, the other was changed, but ok=2 in the summary

Any thoughts would be appreciated

Thanks a lot,  
Guy

---

<div class="post-metadata">

**Author:** ![Guy\_Matz1](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@Guy\_Matz1](https://forum.ansible.com/u/Guy_Matz1)\
**Post date:** [June 15, 2019, 5:07pm UTC](https://forum.ansible.com/t/changed-when-in-a-loop-gets-lost/30574/2 "2019-06-15T17:07:38Z")

</div>

oops!

ansible --version  
ansible 2.8.0  
config file = /Users/matz/Code/schransible/ansible.cfg  
configured module search path = [‘/Users/matz/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]  
ansible python module location = /Users/matz/Code/schransible/venv/lib/python3.7/site-packages/ansible  
executable location = /Users/matz/Code/schransible/venv/bin/ansible  
python version = 3.7.3 (default, Mar 27 2019, 09:23:15) [Clang 10.0.1 (clang-1001.0.46.3)]

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 17, 2019, 2:12pm UTC](https://forum.ansible.com/t/changed-when-in-a-loop-gets-lost/30574/3 "2019-06-17T14:12:49Z")

</div>

This appears to be a bug in the default callback plugin, and only with `debug`. If you use some other task like `ping`, it would show it.

The callback plugin “cleans” the result using `self._clean_results` in `v2_runner_item_on_ok` which strips `changed` from `debug` tasks, as such the callback no longer has knowledge of whether the iteration resulted in a change.

I’d recommend filing an issue on github.
