# When conditional bug in Ansible 2.0.0.2 ?

**URL:** <https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539>\
**Category:** Ansible Project\
**Created:** [February 11, 2016, 1:38pm UTC](https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539 "2016-02-11T13:38:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [February 11, 2016, 1:38pm UTC](https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539/1 "2016-02-11T13:38:26Z")

</div>

Hi List,

So I got this great thing here:

```auto
- name: Copy custom nrpe plugins
template:
src: "{{ item }}"
dest: "{{ nrpe.plugins }}"
mode: 0755
owner: "{{ nrpe.user }}"
group: "{{ nrpe.user }}"
tags: update_nrpe

notify: restart nrpe
with_fileglob: "../templates/plugins/{{ nrpe_scripts }}/*"
when: nrpe_scripts is defined

```

Works a treat with 1.9, it would be really easy to add service checks for special server cases.

With Ansible 2.0.0.2 this breaks, because 2.0 tries to fill the fileglob before looking at the when: conditional. And since the nrpe\_scripts is not defined for most servers, it breaks!

An ugly hack would be to put a general variable in group\_vars/all that just makes it look into an empty directory or something.

Is this a bug? or intended?

Thanks,  
Mark

---

<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:** [February 11, 2016, 1:42pm UTC](https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539/2 "2016-02-11T13:42:37Z")

</div>

This is expected. `when` statements work on each iteration of the `with_` loop, and as such the `when` statements are effectively inspected _after_ `with_` loops.

Ansible 1.9 may have allowed this to pass due to a bug in logic, however 2.0 is more strict, and is properly failing.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [February 11, 2016, 2:09pm UTC](https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539/3 "2016-02-11T14:09:32Z")

</div>

Interesting.

But people would expect a time of “deprecated but works” at the least.  
And besides, I find the original way more logical. (Which will be so for more people, necessitating a deprecation warning, not a complete failure)

I’m noticing a lot of stuff gone, sort of broken, changed behavior, between these two ansible versions. Not good for the mindset of people who I just managed to get onboard with Ansible.

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 11, 2016, 3:20pm UTC](https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539/4 "2016-02-11T15:20:23Z")

</div>

The previous exception was ignored in this case, 2.0 does not ignore exceptions, that is the main difference.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [February 11, 2016, 6:50pm UTC](https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539/5 "2016-02-11T18:50:01Z")

</div>

Understood, we can call it all kinds of things, but companies and/or teams have been building playbooks with these things. They are now breaking.  
One team I know is now using it as an excuse to start using puppet again as “Ansible is still a moving target”.

This isn’t a rant. … …well maybe a litte 😉 But it’s also an observation. Ansible really needs to be carefull with these sort of changes. I don’t want people to turn to other things because of things like this.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 11, 2016, 6:52pm UTC](https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539/6 "2016-02-11T18:52:29Z")

</div>

I’m not saying that it is not a problem, just that it is not as easy to mark as ‘deprecated’ when there was no knob to ‘turn off this feature’ but a general tightening on propagating and capturing errors.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 11, 2016, 7:21pm UTC](https://forum.ansible.com/t/when-conditional-bug-in-ansible-2-0-0-2/20539/7 "2016-02-11T19:21:18Z")

</div>

see if this helps [https://github.com/ansible/ansible/pull/14441](https://github.com/ansible/ansible/pull/14441)
