Conditional problems with Ansible 2.5.0

410 views
Skip to first unread message

Trond Hindenes

unread,
Mar 24, 2018, 5:45:30 AM3/24/18
to Ansible Project
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?



Trond Hindenes

unread,
Mar 24, 2018, 5:50:06 AM3/24/18
to Ansible Project
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 "<var> 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.

Kai Stian Olstad

unread,
Mar 24, 2018, 6:19:53 AM3/24/18
to ansible...@googlegroups.com
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.

--
Kai Stian Olstad

Trond Hindenes

unread,
Mar 24, 2018, 7:53:57 AM3/24/18
to Ansible Project
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!

Trond Hindenes

unread,
Mar 24, 2018, 8:01:21 AM3/24/18
to Ansible Project
about win_chocolatey: It's strange that it doesnt emit an "rc" anymore, it certainly doesn't match the documentation:

Trond Hindenes

unread,
Mar 24, 2018, 8:13:27 AM3/24/18
to Ansible Project
oh, it only emits it on change. Not sure how I feel about that.
Reply all
Reply to author
Forward
0 new messages