2019-05-10 15:06:48 +00:00
|
|
|
- hosts: localhost
|
|
|
|
tasks:
|
|
|
|
- name: Import SSH key pair
|
|
|
|
ec2_key:
|
|
|
|
name: "{{ key_name }}"
|
|
|
|
key_material: "{{ lookup('file', ssh_key_dir + '/id_rsa.pub') }}"
|
|
|
|
|
|
|
|
- name: Create instance
|
|
|
|
ec2_instance:
|
2020-01-09 10:40:02 +00:00
|
|
|
name: "Composer-Test-{{ ami_id }}"
|
2019-05-10 15:06:48 +00:00
|
|
|
image_id: "{{ ami_id }}"
|
|
|
|
key_name: "{{ key_name }}"
|
2020-01-09 10:40:02 +00:00
|
|
|
instance_type: "{{ instance_type }}"
|
2019-05-10 15:06:48 +00:00
|
|
|
security_group: allow-ssh
|
|
|
|
instance_initiated_shutdown_behavior: terminate
|
|
|
|
state: present
|
|
|
|
register: ec2
|
|
|
|
|
|
|
|
- name: Wait for SSH to come up
|
|
|
|
wait_for:
|
|
|
|
host: "{{ item.public_ip_address }}"
|
|
|
|
port: 22
|
|
|
|
state: started
|
|
|
|
with_items: "{{ ec2.instances }}"
|
2019-08-19 12:33:13 +00:00
|
|
|
when: item.image_id == ami_id
|
2019-05-10 15:06:48 +00:00
|
|
|
|
|
|
|
- name: Save instance ID
|
|
|
|
local_action: copy content={{ item.instance_id }} dest={{ tmp_dir }}/instance_id
|
|
|
|
with_items: "{{ ec2.instances }}"
|
2019-08-19 12:33:13 +00:00
|
|
|
when: item.image_id == ami_id
|
2019-05-10 15:06:48 +00:00
|
|
|
|
|
|
|
- name: Save public IP
|
|
|
|
local_action: copy content={{ item.public_ip_address }} dest={{ tmp_dir }}/public_ip
|
|
|
|
with_items: "{{ ec2.instances }}"
|
2019-08-19 12:33:13 +00:00
|
|
|
when: item.image_id == ami_id
|