Reload inventory variables inside playbook execution

510 views
Skip to first unread message

Bruno Galindro da Costa

unread,
Jul 9, 2015, 6:47:29 PM7/9/15
to ansible...@googlegroups.com
I need create an ec2 instance and execute many tasks on it. For accomplish this, I've build two playbooks: one for ec2 creation and other for configuration (package installation, application deploy, etc...). I've created a third playbook that calls booth using include statements. I've called it instance_up.yml

---
- include: creation.yml
- include: configuration.yml



The configuration playbook will try to find EC2 instances with tag ansible = v3hi. This tag and its value are converted into a variable called ec2_tag_ansible_v3hi by ec2.py script each time it finds an instance with that tag before the instance_up.yml execution. But, that variable isn't available for me because the virtual machine isn't already created by creation.yml. So, I think I need to execute ec2.py script between those two playbooks for update all inventory variables. How could I do this?


Igor Cicimov

unread,
Jul 11, 2015, 3:55:21 AM7/11/15
to ansible...@googlegroups.com
May I ask why would you not go with the usual way of adding the newly created instance to a new host group and then configure it? As in the example from the ec2 page:

- name: Create a sandbox instance
hosts: localhost
gather_facts: False
vars:
key_name: my_keypair
instance_type: m1.small
security_group: my_securitygroup
image: my_ami_id
region: us-east-1
tasks:
- name: Launch instance
ec2:
key_name: "{{ keypair }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
wait: true
region: "{{ region }}"
vpc_subnet_id: subnet-29e63245
assign_public_ip: yes
register: ec2
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname=launched
with_items: ec2.instances
- name: Wait for SSH to come up
wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
with_items: ec2.instances

- name: Configure instance(s)
hosts: launched
sudo: True
gather_facts: True
tasks:
- include: config.yml
- include: config2.yml
....
Reply all
Reply to author
Forward
0 new messages