2019-06-28 12:28:47 +02:00
|
|
|
- block:
|
|
|
|
- name: Make instance in a default subnet of the VPC
|
|
|
|
ec2_instance:
|
|
|
|
name: "{{ resource_prefix }}-test-default-vpc"
|
2019-10-21 14:55:44 +02:00
|
|
|
image_id: "{{ ec2_ami_image }}"
|
2019-06-28 12:28:47 +02:00
|
|
|
tags:
|
|
|
|
TestId: "{{ resource_prefix }}"
|
|
|
|
security_groups: "{{ sg.group_id }}"
|
2019-10-21 14:55:44 +02:00
|
|
|
instance_type: "{{ ec2_instance_type }}"
|
2019-06-28 12:28:47 +02:00
|
|
|
wait: false
|
|
|
|
register: in_default_vpc
|
2018-10-11 20:21:01 +02:00
|
|
|
|
2019-06-28 12:28:47 +02:00
|
|
|
- name: Make instance in a default subnet of the VPC(check mode)
|
|
|
|
ec2_instance:
|
|
|
|
name: "{{ resource_prefix }}-test-default-vpc-checkmode"
|
2019-10-21 14:55:44 +02:00
|
|
|
image_id: "{{ ec2_ami_image }}"
|
2019-06-28 12:28:47 +02:00
|
|
|
tags:
|
|
|
|
TestId: "{{ resource_prefix }}"
|
|
|
|
security_groups: "{{ sg.group_id }}"
|
2019-10-21 14:55:44 +02:00
|
|
|
instance_type: "{{ ec2_instance_type }}"
|
2019-06-28 12:28:47 +02:00
|
|
|
check_mode: yes
|
2018-10-11 20:21:01 +02:00
|
|
|
|
2019-06-28 12:28:47 +02:00
|
|
|
- name: "fact presented ec2 instance"
|
|
|
|
ec2_instance_info:
|
|
|
|
filters:
|
|
|
|
"tag:Name": "{{ resource_prefix }}-test-default-vpc"
|
|
|
|
register: presented_instance_fact
|
2018-10-11 20:21:01 +02:00
|
|
|
|
2019-06-28 12:28:47 +02:00
|
|
|
- name: "fact checkmode ec2 instance"
|
|
|
|
ec2_instance_info:
|
|
|
|
filters:
|
|
|
|
"tag:Name": "{{ resource_prefix }}-test-default-vpc-checkmode"
|
|
|
|
register: checkmode_instance_fact
|
2018-10-11 20:21:01 +02:00
|
|
|
|
2019-06-28 12:28:47 +02:00
|
|
|
- name: "Confirm whether the check mode is working normally."
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "{{ presented_instance_fact.instances | length }} > 0"
|
|
|
|
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
2018-10-11 20:21:01 +02:00
|
|
|
|
2019-10-21 14:55:44 +02:00
|
|
|
- name: Terminate instances
|
|
|
|
ec2_instance:
|
2019-06-28 12:28:47 +02:00
|
|
|
instance_ids: "{{ in_default_vpc.instance_ids }}"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
always:
|
|
|
|
- name: Terminate test-default-vpc instance
|
2019-10-21 14:55:44 +02:00
|
|
|
ec2_instance:
|
2019-06-28 12:28:47 +02:00
|
|
|
filters:
|
|
|
|
"tag:Name": "{{ resource_prefix }}-test-default-vpc"
|
|
|
|
state: absent
|
2019-10-21 14:55:44 +02:00
|
|
|
wait: false
|
2019-06-28 12:28:47 +02:00
|
|
|
ignore_errors: yes
|