# AnsibleUndefined in Tower execution

**URL:** <https://forum.ansible.com/t/ansibleundefined-in-tower-execution/37826>\
**Category:** Ansible Project\
**Created:** [March 29, 2023, 5:17pm UTC](https://forum.ansible.com/t/ansibleundefined-in-tower-execution/37826 "2023-03-29T17:17:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AharonuReddy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aharonureddy/32/5464_2.png) [@AharonuReddy](https://forum.ansible.com/u/AharonuReddy)\
**Post date:** [March 29, 2023, 5:17pm UTC](https://forum.ansible.com/t/ansibleundefined-in-tower-execution/37826/1 "2023-03-29T17:17:28Z")

</div>

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](http://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.”}
