You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This may not be a bug but just something I got away with on older versions but with Ansible 2.3 RC1 if I am checking if a variable registered by a module (with an when clause) is defined and then subsequently get a sub dict value it will fail in 2.3 while in 2.2 and below it works fine. This specifically happens when the module that registers the variable is skipped for any reason and then a subsequent task checks if the variable is defined and then gets the sub key.
STEPS TO REPRODUCE
Example playbook
---
- name: testhosts: localhostconnection: localtasks:
- name: module that won't runstat:
path: /apps/tmpregister: testwhen: False
- name: debug of vardebug:
var: test
- name: test with conditionaldebug:
msg: Awhen: test is defined and test.stat.exists
PLAY [test] ************************************************************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************************************
Friday 17 March 2017 15:20:42 +1000 (0:00:00.039) 0:00:00.039 **********
ok: [localhost]
META: ran handlers
TASK [module that won't run] *******************************************************************************************************************************************************
task path: /apps/dev/playbook/jordan/mr-ansible/test.yml:7
Friday 17 March 2017 15:20:44 +1000 (0:00:01.093) 0:00:01.133 **********
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional result was False", "skipped": true}
TASK [debug of var] ****************************************************************************************************************************************************************
task path: /apps/dev/playbook/jordan/mr-ansible/test.yml:13
Friday 17 March 2017 15:20:44 +1000 (0:00:00.012) 0:00:01.145 **********
ok: [localhost] => {
"changed": false,
"test": {
"changed": false,
"skip_reason": "Conditional result was False",
"skipped": true
}
}
TASK [test with conditional] *******************************************************************************************************************************************************
task path: /apps/dev/playbook/jordan/mr-ansible/test.yml:17
Friday 17 March 2017 15:20:44 +1000 (0:00:00.034) 0:00:01.180 **********
fatal: [localhost]: FAILED! => {"failed": true, "msg": "The conditional check 'test is defined and test.stat.exists' failed. The error was: error while evaluating conditional (test is defined and test.stat.exists): 'dict object' has no attribute 'stat'\n\nThe error appears to have been in '/apps/dev/playbook/jordan/mr-ansible/test.yml': line 17, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: test with conditional\n ^ here\n"}
PLAY RECAP *************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=1
The text was updated successfully, but these errors were encountered:
Since you are skipping the 'stat' task, you still get test as a defined dictionary, but it does not have a stat key which is why you get the CORRECT error message. To avoid issues like this you need:
when: test is defined and 'stat' in test and test.stat.exists
Thank you once again for this and your interest in Ansible!
ISSUE TYPE
COMPONENT NAME
core
ANSIBLE VERSION
CONFIGURATION
Standard
OS / ENVIRONMENT
RHEL 6.7
SUMMARY
This may not be a bug but just something I got away with on older versions but with Ansible 2.3 RC1 if I am checking if a variable registered by a module (with an when clause) is defined and then subsequently get a sub dict value it will fail in 2.3 while in 2.2 and below it works fine. This specifically happens when the module that registers the variable is skipped for any reason and then a subsequent task checks if the variable is defined and then gets the sub key.
STEPS TO REPRODUCE
Example playbook
EXPECTED RESULTS
When using Ansible 2.2.1.0
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: