# equality not consistent

**URL:** <https://forum.ansible.com/t/equality-not-consistent/31752>\
**Category:** Ansible Project\
**Created:** [November 29, 2019, 11:16pm UTC](https://forum.ansible.com/t/equality-not-consistent/31752 "2019-11-29T23:16:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [November 29, 2019, 11:16pm UTC](https://forum.ansible.com/t/equality-not-consistent/31752/1 "2019-11-29T23:16:05Z")

</div>

I assume I’m making some strange error here, but I cannot figure out what the error is.

I have a “changed\_when” clause I’ve constructed that never seems to work. However, if I take out the clause into its own debug statement, it seems to work.

I have reproduced this with the following ansible:

`

- hosts: localhost  
gather\_facts: False  
tasks:

- name: Update Jenkins-Jobs on Jenkins Master - docker container  
command: |  
echo "INFO:jenkins\_jobs.cli.subcommand.update:Updating jobs in [‘./jobs/’] ()  
INFO:root:Caching type parameters of parameters = jenkins\_jobs.modules.parameters:Parameters  
INFO:root:Caching type builders of builders = jenkins\_jobs.modules.builders:Builders  
INFO:jenkins\_jobs.builder:Number of jobs generated: 1  
INFO:jenkins\_jobs.cli.subcommand.update:Number of jobs updated: 0  
INFO:jenkins\_jobs.builder:Number of views generated: 0  
INFO:jenkins\_jobs.cli.subcommand.update:Number of views updated: 0  
"  
register: jjb\_update  
changed\_when:

- ( jjb\_update.stdout\_lines | regex\_replace(‘._jobs updated.\s+(\d+)._’, ‘\1’) != ‘0’ )

- name: Number of jobs updated  
debug:  
msg: |  
{{ jjb\_update.stdout\_lines | regex\_replace(‘._jobs updated.\s+(\d+)._’, ‘\1’) }}

- name: Number of jobs updated equals 0?  
debug:  
msg: |  
{{ jjb\_update.stdout\_lines | regex\_replace(‘._jobs updated.\s+(\d+)._’, ‘\1’) == ‘0’ }}

`

The output I get in both 2.8.6 and 2.9.1 is

`

TASK [Update Jenkins-Jobs on Jenkins Master - docker container] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [localhost]

TASK [Number of jobs updated] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “0\n”  
}

TASK [Number of jobs updated equals 0?] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “True\n”  
}

`

If the output is 0 and the check is true, the first task should NOT show changed.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 30, 2019, 9:29am UTC](https://forum.ansible.com/t/equality-not-consistent/31752/2 "2019-11-30T09:29:34Z")

</div>

jjb\_update.stdout\_lines is a list and the regex\_replace filter work on strings, so it probably should have failed.

You can use the search test instead on stdout

&nbsp;&nbsp;&nbsp;changed\_when: jjb\_update.stdout is not search('jobs updated:.0')

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [January 11, 2020, 6:40am UTC](https://forum.ansible.com/t/equality-not-consistent/31752/3 "2020-01-11T06:40:56Z")

</div>

This seems to have been some sort of quoting issue.

After much troubleshooting, I found the working solution:

changed\_when:

- ((jjb\_update.stderr\_lines | regex\_replace(‘._jobs updated.\s+(\d+)._’, ‘\1’)) != ‘0’ )
