I have an inventory file like this:
[redisservers]
72.14.178.81
[webservers]
198.58.107.247
I'm trying to run this playbook against the redisservers group to allow access to port 6379 for the webservers:
---
- name: Allow port 6379 (Redis) access to Web servers
ufw: rule=allow interface=eth0 direction=in port=6379 proto=tcp src="{{ hostvars[item]['ansible_eth0']['ipv4']['address'] }}"
with_items: groups['webservers']
But I'm getting this error:
TASK: [redis | Allow port 6379 (Redis) access to Web servers] *****************
fatal: [72.14.178.81] => One or more undefined variables: 'dict object' has no attribute 'ansible_eth0'
FATAL: all hosts have already failed -- aborting
I've tried simplifying the playbook to refer to the exact server in question to remove the looping:
---
- name: Allow port 6379 (Redis) access to Web servers
ufw: rule=allow interface=eth0 direction=in port=6379 proto=tcp src="{{ hostvars[groups['webservers'][0]]['ansible_eth0']['ipv4']['address'] }}"
and also
---
- name: Allow port 6379 (Redis) access to Web servers
ufw: rule=allow interface=eth0 direction=in port=6379 proto=tcp src="{{ hostvars['198.58.107.247']['ansible_eth0']['ipv4']['address'] }}"
But I'm still getting the same error.
Any hints as to what I'm doing wrong or how I can continue to debug this? I'm using Ansible 1.7.1.