2017-09-26 23:32:47 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Launch new instance(s)
|
|
|
|
ec2:
|
|
|
|
state: present
|
2020-06-18 17:52:10 +02:00
|
|
|
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 }}"
|
2017-09-26 23:32:47 +02:00
|
|
|
wait: yes
|
|
|
|
register: ec2
|
|
|
|
|
|
|
|
- name: Add newly created instance(s) to inventory
|
|
|
|
add_host:
|
2020-06-18 17:52:10 +02:00
|
|
|
hostname: "{{ item.public_dns_name }}"
|
2017-09-26 23:32:47 +02:00
|
|
|
groupname: launched-instances
|
|
|
|
ansible_user: admin
|
|
|
|
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
|
2020-06-18 17:52:10 +02:00
|
|
|
with_items: "{{ ec2.instances }}"
|
2017-09-26 23:32:47 +02:00
|
|
|
|
|
|
|
- debug:
|
2020-06-18 17:52:10 +02:00
|
|
|
msg: "Your newly created instance is reachable at: {{ item.public_dns_name }}"
|
|
|
|
with_items: "{{ 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
|
2020-06-18 17:52:10 +02:00
|
|
|
host: "{{ item.public_dns_name }}"
|
2017-09-26 23:32:47 +02:00
|
|
|
port: 22
|
|
|
|
timeout: 120
|
2020-06-18 17:52:10 +02:00
|
|
|
with_items: "{{ ec2.instances }}"
|