Hello,
Has anyone found the correct syntax for launching a temporary ec2 instance with Ansible, doing some config on it, then using the newly created ip address of the ec2 instance in the
the host inventory.
This part is all good:
---
- name: Base-API-AMI | Create a Base-AMI for the API ECS Cluster
hosts: localhost
connection: local
gather_facts: False
tasks:
- name: check that env was passed in extra-vars
assert:
that: 'env is defined'
- include_vars: "{{ inventory_dir }}/vars/{{ env }}.yml"
- name: create Temporary Instance based on CentOS 7
ec2:
key_name: "{{ key_name }}"
instance_type: t2.micro
image: ami-d2c924b2
instance_tags:
name: dockerhost
wait: true
region: us-west-2
assign_public_ip: no
register: ec2
- debug: var=ec2
-------------- This part fails --------------------------------
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }}
with_items: ec2.instances
----------- this pattern also fails
- name: change hosts inventory
hosts: launched
sudo: True
gather_facts: True
Thanks,
Bill