Hi all,
I'm a bit confused about the behavior of add_host when used from inside a
role or directly in the playbook.
Am I doing something wrong or am I just hitting some role's scope boundary?
THIS WORKS (from the playbook)
---
- name: "provision Ec2"
hosts: localhost
connection: local
gather_facts: false
tasks:
- ec2_instance:
name: "{{ ec2_name }}"
security_groups:
[ecc ecc....]
register: ec2_result
- name: Add new instance to launched group
hosts: localhost
tasks:
- add_host:
hostname: "{{ item.network_interfaces[0].private_ip_address }}"
groupname: launched
with_items: "{{ ec2_result.instances }}"
- name: "config service inside EC2"
hosts: launched
tasks:
[perform config of inside the EC2 ...]
THIS DOES NOT WORK (from inside a role)
Here I'm just encapsulating the EC2 provisioning logic in a role called
'ec2'.
The second play ("config service inside EC2") is skipped because the host
is not present in the in memory inventory.
---
- name: "create ec2 common linux"
hosts: localhost
connection: local
gather_facts: false
roles:
- ec2
tasks:
- meta: refresh_inventory
- name: "config service inside EC2"
hosts: launched
tasks:
[perform config of inside the EC2 ...]
./roles/ec2/tasks/main.yml
---
- name: "provision Ec2"
hosts: localhost
connection: local
gather_facts: false
tasks:
- ec2_instance:
name: "{{ ec2_name }}"
security_groups:
[ecc ecc....]
register: ec2_result
- name: Add new instance to launched group
hosts: localhost
tasks:
- add_host:
hostname: "{{ item.network_interfaces[0].private_ip_address }}"
groupname: launched
with_items: "{{ ec2_result.instances }}"
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7866f762-0d10-4438-9ba1-0d1c12181b1f%40googlegroups.com.