I am configuring nodes that are in rackspace/digitalocean/aws/google cloud and need to access the external IP of the ec2 instances in a template in ansible.
I want to define my machines in the host file like this:
taps_1 ansible_host=54.123.456.789 dc=aws-richmond provider=aws
and then in a template (like one for iptables):
-A FWR -ieth0 -p tcp -s {{ hostvars[host].ansible_host }} --dport 80 -j ACCEPT
but that value doesn't exist :/ if I use the ansible_fqdn
or the IP provided on the ansible_default_ipv4
I only get the internal IP (e.g. 172.31.50.181
)
We have been defining our infra like this:
54.123.456.789 name=taps_1 dc=aws-richmond provider=aws
and accessing by doing hostvars[host].inventory_name
, but I would like to not do that.
Ideas?