2019-10-21 14:55:44 +02:00
|
|
|
- block:
|
|
|
|
- name: New instance and don't wait for it to complete
|
|
|
|
ec2_instance:
|
|
|
|
name: "{{ resource_prefix }}-test-no-wait"
|
|
|
|
image_id: "{{ ec2_ami_image }}"
|
|
|
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
|
|
|
tags:
|
|
|
|
TestId: "{{ resource_prefix }}"
|
|
|
|
wait: false
|
|
|
|
instance_type: "{{ ec2_instance_type }}"
|
|
|
|
register: in_test_vpc
|
2019-03-06 13:46:37 +01:00
|
|
|
|
2019-10-21 14:55:44 +02:00
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- in_test_vpc is not failed
|
|
|
|
- in_test_vpc is changed
|
|
|
|
- in_test_vpc.instances is not defined
|
|
|
|
- in_test_vpc.instance_ids is defined
|
|
|
|
- in_test_vpc.instance_ids | length > 0
|
2019-03-06 13:46:37 +01:00
|
|
|
|
2019-10-21 14:55:44 +02:00
|
|
|
- name: New instance and don't wait for it to complete ( check mode )
|
|
|
|
ec2_instance:
|
|
|
|
name: "{{ resource_prefix }}-test-no-wait-checkmode"
|
|
|
|
image_id: "{{ ec2_ami_image }}"
|
|
|
|
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
|
|
|
tags:
|
|
|
|
TestId: "{{ resource_prefix }}"
|
|
|
|
wait: false
|
|
|
|
instance_type: "{{ ec2_instance_type }}"
|
|
|
|
check_mode: yes
|
2019-03-06 13:46:37 +01:00
|
|
|
|
2019-10-21 14:55:44 +02:00
|
|
|
- name: Facts for ec2 test instance
|
|
|
|
ec2_instance_info:
|
|
|
|
filters:
|
|
|
|
"tag:Name": "{{ resource_prefix }}-test-no-wait"
|
|
|
|
register: real_instance_fact
|
|
|
|
until: real_instance_fact.instances | length > 0
|
|
|
|
retries: 10
|
2019-03-06 13:46:37 +01:00
|
|
|
|
2019-10-21 14:55:44 +02:00
|
|
|
- name: Facts for checkmode ec2 test instance
|
|
|
|
ec2_instance_info:
|
|
|
|
filters:
|
|
|
|
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
|
|
|
register: checkmode_instance_fact
|
2019-03-06 13:46:37 +01:00
|
|
|
|
2019-10-21 14:55:44 +02:00
|
|
|
- name: "Confirm whether the check mode is working normally."
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "{{ real_instance_fact.instances | length }} > 0"
|
|
|
|
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
2019-03-06 13:46:37 +01:00
|
|
|
|
2019-10-21 14:55:44 +02:00
|
|
|
- name: Terminate instances
|
|
|
|
ec2_instance:
|
|
|
|
instance_ids: "{{ in_test_vpc.instance_ids }}"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
always:
|
|
|
|
- name: Terminate test-ebs-vols instances
|
|
|
|
ec2_instance:
|
|
|
|
filters:
|
|
|
|
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
|
|
|
state: absent
|
|
|
|
wait: no
|
|
|
|
ignore_errors: yes
|