Hello,
I’ve run into a situation where I need to define a variable of EC2 public IPs so I can pass them into my cassandra nodes as seeds.
The problem being, I don’t know a good way to get the public IPs. I currently use static inventory (blank, just for groups) and dynamic inventory (ec2.py).
So Ideally, I’d be able to do something like
cassandra_seeds: “{{ hostvars[groups[‘tag_service_az_cassandra-a’][ansible_ec2_public_ipv4] }}”
however, this doesn’t work. ‘ansible_ec2_public_ipv4’ is only present when ec2_facts has been run. ec2_facts can only be run on the instance ansible is currently provisioning and I need the cassandra_seeds variable across all my cassandra instances.
Another idea was:
cassandra_seeds: “{% for host in groups[‘tag_service_az_cassandra-a’] %} {{hostvars[host].ansible_ec2_public_ipv4 }} {% end for %}”
Again, this falls apart because ansible_ec2_public_ipv4 isn’t present. None of the ansible_ facts gathered have the public ip, only ec2_facts has it.
I realize I could change ec2.ini to return public ip for vpc instances, but that would break all of my other plays… I need private ips everywhere else, this is the only instance where I need to use public ips.
The only potential solution I have figured out would be to write a record to route53 for this express purpose of recording the public ip, but that seems like a failure on using ansible correctly.
This seems like it should be really easy, What am I missing?