# change in behaviour of "when:"

**URL:** <https://forum.ansible.com/t/change-in-behaviour-of-when/13667>\
**Category:** Ansible Project\
**Created:** [October 12, 2013, 1:15pm UTC](https://forum.ansible.com/t/change-in-behaviour-of-when/13667 "2013-10-12T13:15:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmy\_Tang](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jimmy\_Tang](https://forum.ansible.com/u/Jimmy_Tang)\
**Post date:** [October 12, 2013, 1:15pm UTC](https://forum.ansible.com/t/change-in-behaviour-of-when/13667/1 "2013-10-12T13:15:47Z")

</div>

Hi All,

I currently have this…

**- shell: “[-f /etc/ldap/.done\_slapd] && echo ‘done’ || echo ‘’”**  
**register: result**

**- dpkg\_reconfigure:**  
**pkg: slapd**  
**answers:**  
**slapd/password2: $ldap\_pass**  
**slapd/password1: $ldap\_pass**  
**slapd/invalid\_config: true**  
**shared/organization: $ldap\_org**  
**slapd/no\_configuration: false**  
**slapd/purge\_database: false**  
**slapd/domain: $ldap\_domain**  
**slapd/backend: HDB**  
**when: result.stdout.find(‘done’) == -1**

**- command: touch /etc/ldap/.done\_slapd creates=/etc/ldap/.done\_slapd**

and its failing with

**PLAY [ldap\_master] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\***

**GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\***  
**ok: [192.168.252.102]**

**TASK: [slapd | apt name= state=present] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\***  
**fatal: [192.168.252.102] =\> error while evaluating conditional: {% if result.stdout.find(‘done’) == -1 %} True {% else %} False {% endif %}**

**FATAL: all hosts have already failed – aborting**

**PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\***  
**to retry, use: --limit @/home/jtang/ldap.retry**

**192.168.252.102 : ok=1 changed=0 unreachable=1 failed=0**

This used to work before I recently pulled the latest development version of ansible. It seems to want to do something smart with the result.

Jimmy.

---

<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:** [October 12, 2013, 3:07pm UTC](https://forum.ansible.com/t/change-in-behaviour-of-when/13667/2 "2013-10-12T15:07:37Z")

</div>

If you can share an example that doesn’t require running slapd (how about echo or something?), please file an example ticket in github that reproduces it.

I’m not sure how “latest” you were here but happy to look.

---

<div class="post-metadata">

**Author:** ![Jimmy\_Tang](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jimmy\_Tang](https://forum.ansible.com/u/Jimmy_Tang)\
**Post date:** [October 12, 2013, 3:37pm UTC](https://forum.ansible.com/t/change-in-behaviour-of-when/13667/3 "2013-10-12T15:37:03Z")

</div>

Hi Michael,

I was testing against ansible 8faaae142ce84ae8029520c4d0a4cc343bbc9070, I think I’ve managed to create a test case for this. I’ll test abit more then log a ticket, but it looks like it has to do with roles…

Jimmy

---

<div class="post-metadata">

**Author:** ![Jimmy\_Tang](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jimmy\_Tang](https://forum.ansible.com/u/Jimmy_Tang)\
**Post date:** [October 12, 2013, 6:15pm UTC](https://forum.ansible.com/t/change-in-behaviour-of-when/13667/4 "2013-10-12T18:15:12Z")

</div>

Hi Michael,

Please see [https://github.com/jcftang/vars-failure-evaluation](https://github.com/jcftang/vars-failure-evaluation) I’ve managed to recreate the failure.

Thanks,  
Jimmy

---

<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 12, 2013, 8:55pm UTC](https://forum.ansible.com/t/change-in-behaviour-of-when/13667/5 "2013-10-12T20:55:14Z")

</div>

Thanks, looking at this now!

---

<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 12, 2013, 9:41pm UTC](https://forum.ansible.com/t/change-in-behaviour-of-when/13667/6 "2013-10-12T21:41:46Z")

</div>

Should be good to go now.

This was a result of the work last night to add deprecation warnings, and a variable wasn’t being copied properly while parsing the included tasks, which resulted in conditionals occasionally being applied to tasks they were not intended for.

While cleaning this up, I also took the opportunity to improve the error message on failed conditionals to not present all the internal “if True / False” logic – which the user doesn’t need to know about – when explaining which conditionals failed. That seems to be a popular question so should greatly simplify things.
