2017-09-26 23:32:47 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Launch new instance(s)
|
|
|
|
ec2:
|
|
|
|
state: present
|
|
|
|
aws_access_key: "{{aws_access_key}}"
|
|
|
|
aws_secret_key: "{{aws_secret_key}}"
|
|
|
|
region: "{{aws_region}}"
|
|
|
|
image: "{{ec2_base_ami}}"
|
|
|
|
instance_type: "{{ec2_instance_type}}"
|
|
|
|
count: "{{ec2_instance_count}}"
|
|
|
|
assign_public_ip: "{{ec2_public_ip}}"
|
|
|
|
group: "{{ec2_security_group.name}}"
|
|
|
|
key_name: "{{ec2_keyname}}"
|
|
|
|
wait: yes
|
|
|
|
register: ec2
|
|
|
|
|
|
|
|
- name: Add newly created instance(s) to inventory
|
|
|
|
add_host:
|
|
|
|
hostname: "{{item.public_dns_name}}"
|
|
|
|
groupname: launched-instances
|
|
|
|
ansible_user: admin
|
|
|
|
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
|
2021-05-04 14:18:40 +02:00
|
|
|
loop: "{{ec2.instances}}"
|
2017-09-26 23:32:47 +02:00
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: "Your newly created instance is reachable at: {{item.public_dns_name}}"
|
2021-05-04 14:18:40 +02:00
|
|
|
loop: "{{ec2.instances}}"
|
2017-09-26 23:32:47 +02:00
|
|
|
|
|
|
|
- name: Wait for SSH to come up on all instances (give up after 2m)
|
|
|
|
wait_for:
|
|
|
|
state: started
|
|
|
|
host: "{{item.public_dns_name}}"
|
|
|
|
port: 22
|
|
|
|
timeout: 120
|
2021-05-04 14:18:40 +02:00
|
|
|
loop: "{{ec2.instances}}"
|