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:
`
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:
`
So I wrote a template task that populates this jinja template:
{{ hostvars['198.58.107.247'] }}
And this is the output I got:
{'ansible_ssh_user': 'root', 'inventory_hostname_short': '198', 'group_names': ['webservers'], 'inventory_hostname': '198.58.107.247'}
So hostvars[‘198.58.107.247’] doesn’t seem to be filled with all the facts for that host. Then I realized that the root playbook I’m running (provision.yml) looks like this:
`
In Ansible to use facts about a host you must have either:
already gathered facts from that host in that play (just gathering facts would be enough, no tasks needed)
hosts: webservers:dbservers
tasks:
hosts: webservers # that need to know facts about dbservers
tasks:
…
OR
enabled fact caching and previously talked to that host within the cache timeout
http://docs.ansible.com/playbooks_variables.html#fact-caching