# Conditional problems with Ansible 2.5.0

**URL:** <https://forum.ansible.com/t/conditional-problems-with-ansible-2-5-0/27104>\
**Category:** Ansible Project\
**Created:** [March 24, 2018, 9:45am UTC](https://forum.ansible.com/t/conditional-problems-with-ansible-2-5-0/27104 "2018-03-24T09:45:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [March 24, 2018, 9:45am UTC](https://forum.ansible.com/t/conditional-problems-with-ansible-2-5-0/27104/1 "2018-03-24T09:45:29Z")

</div>

I have the following steps in a playbook:

- name: check if .net 4.7.1 is installed  
script: check\_net\_version.ps1 “4.7.1”  
register: net471result  
changed\_when: false

- name: Install .Net 4.7.1  
win\_chocolatey:  
name: dotnet4.7.1  
register: net471\_exit\_code  
failed\_when: net471\_exit\_code.rc != 0 and net471\_exit\_code.rc != 3010  
when: ‘“missing” in net471result.stdout’

- name: reboot node if needed  
win\_reboot:  
when: net471\_exit\_code.rc is defined and net471\_exit\_code.rc == 3010 and allow\_reboot is defined and (allow\_reboot | bool)

Check if software is missing (using a custom script because some weirdness), install if it is.  
This has worked fine for us in Ansible 2.3.x which we’ve been on until now, but this fails in 2.5.0. Even if I add a check for making sure the “net471\_exit\_code” var exists altogether, it fails:

“msg”: “The conditional check ‘net471\_exit\_code.rc != 0 and net471\_exit\_code.rc != 3010’ failed. The error was: error while evaluating conditional (net471\_exit\_code.rc != 0 and net471\_exit\_code.rc != 3010): ‘dict object’ has no attribute ‘rc’”

It seems to me that there’s some bug in how Ansible evaluates object attributes (or dict keys), so that “net471\_exit\_code.rc is defined” is picked up as a “true” instead of a “false”.

Anyone able to repro?

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [March 24, 2018, 9:50am UTC](https://forum.ansible.com/t/conditional-problems-with-ansible-2-5-0/27104/2 "2018-03-24T09:50:06Z")

</div>

I’ve also tried the “dict-format”:

net471\_exit\_code[‘rc’] is defined

But the same thing happens. I almost get the feeling that Ansible evaluates the entire “chain”, which is a problem with potentially undefined variable (that’s why we test the “ is defined” first, to make the evaluation halt).

If this doesn’t work anymore I’m a bit stumped as to how to build complex conditionals.

---

<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:** [March 24, 2018, 10:19am UTC](https://forum.ansible.com/t/conditional-problems-with-ansible-2-5-0/27104/3 "2018-03-24T10:19:37Z")

</div>

I think this is because win\_chocolatey doesn't return rc anymore so maybe the bug lies there.  
You could check by run win\_chocolatey register and print the result.

I can reproduce this by replacing win\_chocolatey with debug that does not return rc.  
But if I use command module that do return rc it works.

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [March 24, 2018, 11:53am UTC](https://forum.ansible.com/t/conditional-problems-with-ansible-2-5-0/27104/4 "2018-03-24T11:53:56Z")

</div>

Thanks Kai,

Good point - I may have been looking at this all wrong, and not able to repro just playing around with basic set\_fact/conditionals playbooks. I’ll keep researching 🙂

thanks again!

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [March 24, 2018, 12:01pm UTC](https://forum.ansible.com/t/conditional-problems-with-ansible-2-5-0/27104/5 "2018-03-24T12:01:21Z")

</div>

about win\_chocolatey: It’s strange that it doesnt emit an “rc” anymore, it certainly doesn’t match the documentation:  
[http://docs.ansible.com/ansible/2.5/modules/win\_chocolatey\_module.html](http://docs.ansible.com/ansible/2.5/modules/win_chocolatey_module.html)

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [March 24, 2018, 12:13pm UTC](https://forum.ansible.com/t/conditional-problems-with-ansible-2-5-0/27104/6 "2018-03-24T12:13:27Z")

</div>

oh, it only emits it on change. Not sure how I feel about that.
