lorax/tests/cli/playbooks/aws/instance.yml
Jan Stodola ed8a21a627 Use ansible instead of awscli
Not all parts of the script has been switched from awscli to ansible yet,
because the ansible aws modules do not support importing s3 object as snapshots.
(https://github.com/ansible/ansible/issues/53453)
Workaround using the image_location parameter of the ec2_ami ansible module
would mean adding extra code for generating AMI manifest with pre-signed
URLs.
2019-05-24 12:44:30 +03:00

33 lines
933 B
YAML

- 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:
name: "{{ ami_id }}"
image_id: "{{ ami_id }}"
key_name: "{{ key_name }}"
instance_type: t2.small
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 }}"
- name: Save instance ID
local_action: copy content={{ item.instance_id }} dest={{ tmp_dir }}/instance_id
with_items: "{{ ec2.instances }}"
- name: Save public IP
local_action: copy content={{ item.public_ip_address }} dest={{ tmp_dir }}/public_ip
with_items: "{{ ec2.instances }}"