# failed\_when/changed\_when with script module

**URL:** <https://forum.ansible.com/t/failed-when-changed-when-with-script-module/18680>\
**Category:** Ansible Project\
**Created:** [July 5, 2015, 2:32pm UTC](https://forum.ansible.com/t/failed-when-changed-when-with-script-module/18680 "2015-07-05T14:32:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Schrab](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Aaron\_Schrab](https://forum.ansible.com/u/Aaron_Schrab)\
**Post date:** [July 5, 2015, 2:32pm UTC](https://forum.ansible.com/t/failed-when-changed-when-with-script-module/18680/1 "2015-07-05T14:32:52Z")

</div>

I’m using ansible 2.0, and I’m trying to create a script play which will correctly flag when a change was made, but so far I’ve been unable to get this to work. Here’s what I have for the play:

- script: script {{ arg }}  
register: command\_result  
failed\_when: command\_result.rc != 0 and command\_result.rc != 1  
changed\_when: command\_result.rc == 1

The script runs correctly, and reports success if no change happens. But, if it exits with code 1 to indicate that a change was made ansible is reporting that it failed:

fatal: [vagrant]: FAILED! =\> {“stdout”: “”, “changed”: true, “failed”: false, “stderr”: “”, “rc”: 1, “failed\_when\_result”: false}

I’ve also tried using:

- script: script {{ arg }}

register: command\_result  
changed\_when: “‘updated’ in command\_result.stderr”

With the script using stderr rather than the exit status to report the change, but in that case ansible never reports that a change was made.

Is ideas about what I’m doing wrong?

Thanks.
