Here is my role
- name: Launch instance
ec2:
region: ‘{{ region }}’
zone: ‘{{ zone }}’
keypair: ‘{{ keypair }}’
group: ‘{{ security_group }}’
image: ‘{{ image }}’
instance_type: ‘{{ instance_type | default(“t2.micro”) }}’
instance_profile_name: ‘{{ instance_profile_name | default(omit) }}’
count: ‘{{ instance_count | default(1) }}’
vpc_subnet_id: ‘{{vpc_subnet_id | default(omit)}}’
instance_tags: ‘{“Name”:“{{tag_name}}”,“customer”:“{{tag_customer}}”,“project”:“{{tag_project}}”,“roleis”:“{{tag_role}}”,“environment”:“{{env}}”,“node”:“{{tag_node}}”}’
wait: yes
volumes:
device_name: /dev/sdb
device_type: gp2
volume_size: “{{volume_size}}”
delete_on_termination: false
encrypted: true
monitoring: no
register: ec2Use with_items to add each instances public IP to a new hostgroup for use in the next play.
name: Add new instances to host group
add_host:
name: ‘{{item.public_dns_name}}’
groups: launch
with_items: ec2.instancesname: Wait for SSH to be available
wait_for:
host: ‘{{item.public_dns_name}}’
port: 22
delay: 60
timeout: 480
state: started
with_items: ec2.instances
This isn’t working for some reason
ansible 2.0.0 (devel de52cfb5d7)