# AnsibleUndefinedVariable: 'dict object' has no attribute

**URL:** <https://forum.ansible.com/t/ansibleundefinedvariable-dict-object-has-no-attribute/29360>\
**Category:** Ansible Project\
**Created:** [January 3, 2019, 6:04pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-dict-object-has-no-attribute/29360 "2019-01-03T18:04:12Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 7, 2019, 7:57pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-dict-object-has-no-attribute/29360/21 "2019-01-07T19:57:32Z")

</div>

can you do this debug:

- debug: msg={{ hostvars[item]['ansible\_ssh\_host\_key\_ecdsa\_public'] }}  
&nbsp;&nbsp;&nbsp;loop: '{{groups["all"]}}'

---

<div class="post-metadata">

**Author:** ![Freddie\_Eisa](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@Freddie\_Eisa](https://forum.ansible.com/u/Freddie_Eisa)\
**Post date:** [January 7, 2019, 8:13pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-dict-object-has-no-attribute/29360/22 "2019-01-07T20:13:28Z")

</div>

“The task includes an option with an undefined variable. The error was: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘ansible\_ssh\_host\_key\_ecdsa\_public’\n\nThe error appears to have been in ‘/home/feisa/ansible-linux/test\_single\_server.yml’: line 6, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug: msg={{ hostvars[item][‘ansible\_ssh\_host\_key\_ecdsa\_public’] }}\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”

---

<div class="post-metadata">

**Author:** ![Freddie\_Eisa](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@Freddie\_Eisa](https://forum.ansible.com/u/Freddie_Eisa)\
**Post date:** [January 7, 2019, 8:17pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-dict-object-has-no-attribute/29360/23 "2019-01-07T20:17:16Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 7, 2019, 8:23pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-dict-object-has-no-attribute/29360/24 "2019-01-07T20:23:50Z")

</div>

so one of your hosts is not returning the fact for  
`ansible_ssh_host_key_ecdsa_public`, its not an issue with the  
template, but of getting the variable defined in the first place, the  
'item' from the error will tell the first host host it is (add  
ignore\_errors:yes and you'll see all the hosts that fail).

To avoid such issues you might want to use the |default() filter or  
check if the key exists before using it.

---

<div class="post-metadata">

**Author:** ![Freddie\_Eisa](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@Freddie\_Eisa](https://forum.ansible.com/u/Freddie_Eisa)\
**Post date:** [January 7, 2019, 8:37pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-dict-object-has-no-attribute/29360/25 "2019-01-07T20:37:11Z")

</div>

I ran the following

Tasks:

- debug:  
var: ansible\_ssh\_host\_key\_ecdsa\_public

Received this

{  
“ansible\_ssh\_host\_key\_ecdsa\_public”: “AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMj3Y7I/7ByqhoT22sBg2D0tUO8rCVQRTUQXyecCPVfXud9tnInwxXJUI8KKoIScw2YEKQuq8SPB46CE6ce6Bqw=”

[Previous page](https://forum.ansible.com/t/ansibleundefinedvariable-dict-object-has-no-attribute/29360.md?page=1)
