'dict' object has no attribute

317 views
Skip to first unread message

Brad V

unread,
Jun 16, 2015, 11:47:42 AM6/16/15
to ansible...@googlegroups.com
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.

Yassen Damyanov

unread,
Jun 17, 2015, 9:52:27 AM6/17/15
to ansible...@googlegroups.com
How about ansible_eth0.ipv4[0].address ? (note the zero index)

Yassen Damyanov

unread,
Jun 17, 2015, 1:50:00 PM6/17/15
to ansible...@googlegroups.com

On Wednesday, June 17, 2015 at 4:52:27 PM UTC+3, Yassen Damyanov wrote:
How about ansible_eth0.ipv4[0].address ? (note the zero index)

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

Brad V

unread,
Jun 18, 2015, 9:06:07 AM6/18/15
to ansible...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages