Hi all
I’m using ec2 module to launch EC2 instances in one play book, and “-i ec2.py” to query a subset of the instances in a second playbook.
So far so good.
The problem I have is when I started to call both play books, using include, from one “super” playbook.
AFAIU, the inventory did not refresh, so the second one failed.
I can bypass the problem by running both playbooks from a bash script with
./ec2.py --refresh-cache > /dev/null
between them, but it is ugly and cause other problems.
Hi Giovanni
Thanks for the prompt response.
If I’m reading the doc correctly, the new group can only be used in the same playbook.
Is it so?
I’m using more than one playbook, including all of the from one “super” playbook.
add_host affects the 'current run', all subsequent plays will have
access, the distribtion of the plays in different files does not
matter.
ansible reads all the files passed to it (directly or through
includes), compiles the plays and then runs them in order, at this
point the files they came from are irrelevant.
Thanks Brain, Giovanni
I’m confused on when to use ec2.py dynamic inventory and when creating group as you suggested.
If I understand correctly, the first make sense if I want to query info set by others, while the second make more sense if the servers live and die in the scope of my playbook (my use case).
I’m currently using hostvars from ec2.py to get the internal ips of servers:
Found a solution, let me answer myself if anyone is interested
I got a list the internal IPs by creating a new group, as follow:
name: Add instances to private ip group
local_action: add_host name={{item.private_ip}} groupname=CassandraPrivate_{{load_name}}
with_items: ec2.instances