lorax/tests/cli/playbooks/aws/instance.yml
Alexander Todorov d1d30bb974 tests: AWS - apply tags when creating resoures and delete by tags
- for objects in S3 - match filenames starting with Composer-Test
- for keys use the new Composer-Test-Key- prefix (for consistency)
- for VM names use Composer-Test-VM- prefix instead of ami id
2020-02-12 14:58:11 +01:00

38 lines
1.1 KiB
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: "{{ vm_name }}"
tags:
composer-test: true
image_id: "{{ ami_id }}"
key_name: "{{ key_name }}"
instance_type: "{{ instance_type }}"
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 }}"
when: item.image_id == ami_id
- name: Save instance ID
local_action: copy content={{ item.instance_id }} dest={{ tmp_dir }}/instance_id
with_items: "{{ ec2.instances }}"
when: item.image_id == ami_id
- name: Save public IP
local_action: copy content={{ item.public_ip_address }} dest={{ tmp_dir }}/public_ip
with_items: "{{ ec2.instances }}"
when: item.image_id == ami_id