# 'dict' object has no attribute

**URL:** <https://forum.ansible.com/t/dict-object-has-no-attribute/18519>\
**Category:** Ansible Project\
**Created:** [June 16, 2015, 3:45pm UTC](https://forum.ansible.com/t/dict-object-has-no-attribute/18519 "2015-06-16T15:45:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad\_V](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@Brad\_V](https://forum.ansible.com/u/Brad_V)\
**Post date:** [June 16, 2015, 3:45pm UTC](https://forum.ansible.com/t/dict-object-has-no-attribute/18519/1 "2015-06-16T15:45:47Z")

</div>

I’m a bit stumped here.

I have a playbook setup that uses hostvars to fill in expressions in other places including jinja2 templates. Whenever one of those variables is an IP address, I get the error ‘dict’ object has no attribute ‘xx.xx.xx.xx’. when there’s a var set to that value.

For example,

/install/vars/main.yml

db\_master\_ip: “{{hostvars[‘hostname.localdomain’][ansible\_eth0.ipv4.address]}}”

is used in a later step as

/install/tasks/main.yml

- include: standby.yml

/install/tasks/standby.yml  
shell: pg\_basebackup -h {{db\_master\_ip}} -D {{postgres\_data\_dir}} -U {{db\_user}} -v -x

Ansible fails on that step with the ‘dict’ object has no attribute error. Though it shows the correct IP address in the error message

If I change it to

shell: pg\_basebackup -h {{hostvars[‘hostname.localdomain’][ansible\_eth0.ipv4.address]}}

It works just fine, but that’s definitely less than ideal as I use the {{ db\_master\_ip }} expression in quite a few places and would like to be able to easily modify it.

Alternatively, if I change

db\_master\_ip: 192.168.1.2

it also works.

I know it’s got to be something with the way jinja2 is parsing the dict, but I have no idea where it would be going wrong or what I can do to fix it. I’ve been googling around for the last day and haven’t really come up with anything that makes sense to my situation.

---

<div class="post-metadata">

**Author:** ![Yassen\_Damyanov](https://avatars.discourse-cdn.com/v4/letter/y/9fc29f/32.png) [@Yassen\_Damyanov](https://forum.ansible.com/u/Yassen_Damyanov)\
**Post date:** [June 17, 2015, 1:52pm UTC](https://forum.ansible.com/t/dict-object-has-no-attribute/18519/2 "2015-06-17T13:52:27Z")

</div>

How about ansible\_eth0.ipv4[0].address ? (note the zero index)

---

<div class="post-metadata">

**Author:** ![Yassen\_Damyanov](https://avatars.discourse-cdn.com/v4/letter/y/9fc29f/32.png) [@Yassen\_Damyanov](https://forum.ansible.com/u/Yassen_Damyanov)\
**Post date:** [June 17, 2015, 5:50pm UTC](https://forum.ansible.com/t/dict-object-has-no-attribute/18519/3 "2015-06-17T17:50:00Z")

</div>

My bad, this is OpenBSD specific (ansible\_ifname.ipv4 is a list of dicts there). So just forget the above.  
-Y.

---

<div class="post-metadata">

**Author:** ![Brad\_V](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@Brad\_V](https://forum.ansible.com/u/Brad_V)\
**Post date:** [June 18, 2015, 1:06pm UTC](https://forum.ansible.com/t/dict-object-has-no-attribute/18519/4 "2015-06-18T13:06:07Z")

</div>

Anyone else stumbling upon this.

db\_master\_ip: “{{ hostvars[‘hostname.localdomain’].ansible\_eth0.ipv4.address }}” was the change that was needed.

Thanks to piffey on the IRC channel for the assist.
