Hi Everyone,
I have playbook executed in Ansible server and it is successful but when i execute the same in Tower I am getting 1. AnsibleUndefined, 2. Dict converting to string.
I would like to understand what makes a difference and a solution for it. Thank you.
Under vars i have defined -
vars:
failed_list:
failed_lists: “{{ dict(groups.all| zip(hostvars|dict2items| map(attribute=‘value.failed_list’, default=))) }}”
failed_hosts: “{{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}”
Under ‘rescue’ section -
rescue:
- set_fact: failed_list: “{{ failed_list + [ansible_failed_task.name] }}”
Below output for:
- name: failed_lists | groups all | hostvars|dict2items | attribute=‘value.failed_list’ | dict
debug:
msg: “{{ dict(groups.all | zip(hostvars| dict2items | map(attribute=‘value.failed_list’, default=))) }}”
Result in server:
TASK [failed_lists | groups all | hostvars|dict2items | attribute=‘value.failed_list’ | dict] ***********************************************************************************************************************************************
ok: [TestCluster1] => {}
MSG:
{‘TestCluster1’: [‘Aggregate Information gathering’], ‘Cluster1’: , ‘Cluster2’: , ‘TestCluster2’: [‘Aggregate Information gathering’]}
ok: [Cluster1] => {}
MSG:
{‘TestCluster1’: [‘Aggregate Information gathering’], ‘Cluster1’: , ‘Cluster2’: , ‘TestCluster2’: [‘Aggregate Information gathering’]}
ok: [Cluster2] => {}
MSG:
{‘TestCluster1’: [‘Aggregate Information gathering’], ‘Cluster1’: , ‘Cluster2’: , ‘TestCluster2’: [‘Aggregate Information gathering’]}
ok: [TestCluster2] => {}
MSG:
{‘TestCluster1’: [‘Aggregate Information gathering’], ‘Cluster1’: , ‘Cluster2’: , ‘TestCluster2’: [‘Aggregate Information gathering’]}
Tower output:
TASK [failed_lists | groups all | hostvars|dict2items | attribute=‘value.failed_list’ | dict] ***
ok: [Cluster1] => {
“msg”: “{‘Cluster1’: AnsibleUndefined, ‘Cluster2’: AnsibleUndefined, ‘TestCluster’: [‘Aggregate Information gathering’], ‘TestCluster2’: [‘Aggregate Information gathering’]}”
}
ok: [Cluster2] => {
“msg”: “{‘Cluster1’: AnsibleUndefined, ‘Cluster2’: AnsibleUndefined, ‘TestCluster’: [‘Aggregate Information gathering’], ‘TestCluster2’: [‘Aggregate Information gathering’]}”
}
ok: [TestCluster] => {
“msg”: “{‘Cluster1’: AnsibleUndefined, ‘Cluster2’: AnsibleUndefined, ‘TestCluster’: [‘Aggregate Information gathering’], ‘TestCluster2’: [‘Aggregate Information gathering’]}”
}
ok: [TestCluster2] => {
“msg”: “{‘Cluster1’: AnsibleUndefined, ‘Cluster2’: AnsibleUndefined, ‘TestCluster’: [‘Aggregate Information gathering’], ‘TestCluster2’: [‘Aggregate Information gathering’]}”
}
TASK [print failed_hosts] ******************************************************
fatal: [Cluster1]: FAILED! => {“msg”: “An unhandled exception occurred while templating ‘{{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}’. Error was a <class ‘ansible.errors.AnsibleError’>, original message: Unexpected templating type error occurred on ({{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}): dict2items requires a dictionary, got <class ‘str’> instead.”}
fatal: [Cluster2]: FAILED! => {“msg”: “An unhandled exception occurred while templating ‘{{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}’. Error was a <class ‘ansible.errors.AnsibleError’>, original message: Unexpected templating type error occurred on ({{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}): dict2items requires a dictionary, got <class ‘str’> instead.”}
fatal: [TestCluster]: FAILED! => {“msg”: “An unhandled exception occurred while templating ‘{{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}’. Error was a <class ‘ansible.errors.AnsibleError’>, original message: Unexpected templating type error occurred on ({{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}): dict2items requires a dictionary, got <class ‘str’> instead.”}
fatal: [TestCluster2]: FAILED! => {“msg”: “An unhandled exception occurred while templating ‘{{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}’. Error was a <class ‘ansible.errors.AnsibleError’>, original message: Unexpected templating type error occurred on ({{ failed_lists|dict2items| selectattr(‘value’)| map(attribute=‘key’)|list }}): dict2items requires a dictionary, got <class ‘str’> instead.”}