@ -1,4 +1,5 @@
- name : set connection information for all tasks
- block:
- name : set connection information for all tasks
set_fact:
aws_connection_info : &aws_connection_info
aws_access_key : "{{ aws_access_key }}"
@ -6,7 +7,7 @@
security_token : "{{ security_token }}"
region : "{{ aws_region }}"
no_log : true
- name : Make instance in the testing subnet created in the test VPC
- name : Make instance in the testing subnet created in the test VPC
ec2_instance:
name : "{{ resource_prefix }}-test-basic-vpc-create"
image_id : "{{ ec2_ami_image[aws_region] }}"
@ -26,7 +27,7 @@
<< : *aws_connection_info
register : in_test_vpc
- name : Make instance in the testing subnet created in the test VPC(check mode)
- name : Make instance in the testing subnet created in the test VPC(check mode)
ec2_instance:
name : "{{ resource_prefix }}-test-basic-vpc-create-checkmode"
image_id : "{{ ec2_ami_image[aws_region] }}"
@ -45,7 +46,7 @@
<< : *aws_connection_info
check_mode : yes
- name : Try to re-make the instance, hopefully this shows changed=False
- name : Try to re-make the instance, hopefully this shows changed=False
ec2_instance:
name : "{{ resource_prefix }}-test-basic-vpc-create"
image_id : "{{ ec2_ami_image[aws_region] }}"
@ -61,37 +62,37 @@
instance_type : t2.micro
<< : *aws_connection_info
register : remake_in_test_vpc
- name : "Remaking the same instance resulted in no changes"
- name : "Remaking the same instance resulted in no changes"
assert:
that : not remake_in_test_vpc.changed
- name : check that instance IDs match anyway
- name : check that instance IDs match anyway
assert:
that : 'remake_in_test_vpc.instance_ids[0] == in_test_vpc.instance_ids[0]'
- name : check that source_dest_check was set to false
- name : check that source_dest_check was set to false
assert:
that : 'not remake_in_test_vpc.instances[0].source_dest_check'
- name : "fact presented ec2 instance"
- name : "fact presented ec2 instance"
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-test-basic-vpc-create"
<< : *aws_connection_info
register : presented_instance_fact
- name : "fact checkmode ec2 instance"
- name : "fact checkmode ec2 instance"
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-test-basic-vpc-create-checkmode"
<< : *aws_connection_info
register : checkmode_instance_fact
- name : "Confirm whether the check mode is working normally."
- name : "Confirm whether the check mode is working normally."
assert:
that:
- "{{ presented_instance_fact.instances | length }} > 0"
- "{{ checkmode_instance_fact.instances | length }} == 0"
- name : Alter it by adding tags
- name : Alter it by adding tags
ec2_instance:
name : "{{ resource_prefix }}-test-basic-vpc-create"
image_id : "{{ ec2_ami_image[aws_region] }}"
@ -104,17 +105,17 @@
<< : *aws_connection_info
register : add_another_tag
- ec2_instance_info:
- ec2_instance_info:
instance_ids : "{{ add_another_tag.instance_ids }}"
<< : *aws_connection_info
register : check_tags
- name : "Remaking the same instance resulted in no changes"
- name : "Remaking the same instance resulted in no changes"
assert:
that:
- check_tags.instances[0].tags.Another == 'thing'
- check_tags.instances[0].tags.Something == 'else'
- name : Purge a tag
- name : Purge a tag
ec2_instance:
name : "{{ resource_prefix }}-test-basic-vpc-create"
image_id : "{{ ec2_ami_image[aws_region] }}"
@ -127,17 +128,29 @@
instance_type : t2.micro
<< : *aws_connection_info
- ec2_instance_info:
- ec2_instance_info:
instance_ids : "{{ add_another_tag.instance_ids }}"
<< : *aws_connection_info
register : check_tags
- name : "Remaking the same instance resulted in no changes"
- name : "Remaking the same instance resulted in no changes"
assert:
that:
- "'Something' not in check_tags.instances[0].tags"
- name : Terminate instance
- name : check that subnet-default public IP rule was followed
assert:
that:
- check_tags.instances[0].public_dns_name == ""
- check_tags.instances[0].private_ip_address.startswith("10.22.33")
- check_tags.instances[0].subnet_id == testing_subnet_b.subnet.id
- name : check that tags were applied
assert:
that:
- check_tags.instances[0].tags.Name.startswith(resource_prefix)
- "'{{ check_tags.instances[0].state.name }}' in ['pending', 'running']"
- name : Terminate instance
ec2_instance:
filters:
tag:TestId : "{{ resource_prefix }}"
@ -145,27 +158,16 @@
wait : false
<< : *aws_connection_info
register : result
- assert:
- assert:
that : result.changed
- name : Terminate instance
always:
- name : Terminate instance
ec2_instance:
instance_ids : "{{ add_another_tag.instance_ids }}"
filters:
tag:TestId : "{{ resource_prefix }}"
state : absent
wait : false
<< : *aws_connection_info
register : result
- assert:
that : not result.changed
- name : check that subnet-default public IP rule was followed
assert:
that:
- check_tags.instances[0].public_dns_name == ""
- check_tags.instances[0].private_ip_address.startswith("10.22.33")
- check_tags.instances[0].subnet_id == testing_subnet_b.subnet.id
- name : check that tags were applied
assert:
that:
- check_tags.instances[0].tags.Name.startswith(resource_prefix)
- "'{{ check_tags.instances[0].state.name }}' in ['pending', 'running']"
ignore_errors : yes