@ -10,33 +10,55 @@
- block:
- block:
- name : set up aws connection info
set_fact:
aws_connection_info : &aws_connection_info
aws_access_key : "{{ aws_access_key }}"
aws_secret_key : "{{ aws_secret_key }}"
security_token : "{{ security_token }}"
region : "{{ aws_region }}"
no_log : yes
# ============================================================
# ============================================================
- name : create a VPC
- name : create a VPC
ec2_vpc_net:
ec2_vpc_net:
name : "{{ resource_prefix }}-vpc"
name : "{{ resource_prefix }}-vpc"
state : present
state : present
cidr_block : "10.232.232.128/26"
cidr_block : "10.232.232.128/26"
region : '{{ ec2_region }}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
tags:
tags:
Name : "{{ resource_prefix }}-vpc"
Name : "{{ resource_prefix }}-vpc"
Description : "Created by ansible-test"
Description : "Created by ansible-test"
register : vpc_result
register : vpc_result
# ============================================================
- name : create subnet (expected changed=true) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
az : "{{ aws_region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
<< : *aws_connection_info
state : present
check_mode : true
register : vpc_subnet_create
- name : assert creation would happen
assert:
that:
- vpc_subnet_create.changed
- name : create subnet (expected changed=true)
- name : create subnet (expected changed=true)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
az : "{{ ec2_region }}a"
az : "{{ aws _region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
tags:
Name : '{{ec2_vpc_subnet_name}}'
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
Description : '{{ec2_vpc_subnet_description}}'
region : '{{ ec2_region }}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
register : vpc_subnet_create
register : vpc_subnet_create
@ -47,19 +69,34 @@
- 'vpc_subnet_create.subnet.id.startswith("subnet-")'
- 'vpc_subnet_create.subnet.id.startswith("subnet-")'
- '"Name" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Name"] == ec2_vpc_subnet_name'
- '"Name" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Name"] == ec2_vpc_subnet_name'
- '"Description" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
- '"Description" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
# ============================================================
- name : recreate subnet (expected changed=false) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
az : "{{ aws_region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
<< : *aws_connection_info
state : present
check_mode : true
register : vpc_subnet_recreate
- name : assert recreation changed nothing (expected changed=false)
assert:
that:
- 'not vpc_subnet_recreate.changed'
- name : recreate subnet (expected changed=false)
- name : recreate subnet (expected changed=false)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
az : "{{ ec2_region }}a"
az : "{{ aws _region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
tags:
Name : '{{ec2_vpc_subnet_name}}'
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
Description : '{{ec2_vpc_subnet_description}}'
region : '{{ ec2_region }}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
register : vpc_subnet_recreate
register : vpc_subnet_recreate
@ -69,19 +106,56 @@
- 'not vpc_subnet_recreate.changed'
- 'not vpc_subnet_recreate.changed'
- 'vpc_subnet_recreate.subnet == vpc_subnet_create.subnet'
- 'vpc_subnet_recreate.subnet == vpc_subnet_create.subnet'
# ============================================================
- name : update subnet so instances launched in it are assigned an IP (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
az : "{{ aws_region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
<< : *aws_connection_info
state : present
map_public : true
check_mode : true
register : vpc_subnet_modify
- name : assert subnet changed
assert:
that:
- vpc_subnet_modify.changed
- name : update subnet so instances launched in it are assigned an IP
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
az : "{{ aws_region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
<< : *aws_connection_info
state : present
map_public : true
register : vpc_subnet_modify
- name : assert subnet changed
assert:
that:
- vpc_subnet_modify.changed
- vpc_subnet_modify.subnet.map_public_ip_on_launch
# ============================================================
- name : add invalid ipv6 block to subnet (expected failed)
- name : add invalid ipv6 block to subnet (expected failed)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
az : "{{ ec2_region }}a"
az : "{{ aws _region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
ipv6_cidr : 2001 : db8::/64
ipv6_cidr : 2001 : db8::/64
tags:
tags:
Name : '{{ec2_vpc_subnet_name}}'
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
Description : '{{ec2_vpc_subnet_description}}'
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
register : vpc_subnet_ipv6_failed
register : vpc_subnet_ipv6_failed
ignore_errors : yes
ignore_errors : yes
@ -92,19 +166,36 @@
- 'vpc_subnet_ipv6_failed.failed'
- 'vpc_subnet_ipv6_failed.failed'
- "'Couldn\\'t associate ipv6 cidr' in vpc_subnet_ipv6_failed.msg"
- "'Couldn\\'t associate ipv6 cidr' in vpc_subnet_ipv6_failed.msg"
# ============================================================
- name : add a tag (expected changed=true) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
az : "{{ aws_region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
AnotherTag : SomeValue
<< : *aws_connection_info
state : present
check_mode : true
register : vpc_subnet_add_a_tag
- name : assert tag addition happened (expected changed=true)
assert:
that:
- 'vpc_subnet_add_a_tag.changed'
- name : add a tag (expected changed=true)
- name : add a tag (expected changed=true)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
az : "{{ ec2_region }}a"
az : "{{ aws _region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
tags:
Name : '{{ec2_vpc_subnet_name}}'
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
Description : '{{ec2_vpc_subnet_description}}'
AnotherTag : SomeValue
AnotherTag : SomeValue
region : '{{ ec2_region }}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
register : vpc_subnet_add_a_tag
register : vpc_subnet_add_a_tag
@ -116,17 +207,32 @@
- '"Description" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["Description"] == ec2_vpc_subnet_description'
- '"Description" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["Description"] == ec2_vpc_subnet_description'
- '"AnotherTag" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["AnotherTag"] == "SomeValue"'
- '"AnotherTag" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["AnotherTag"] == "SomeValue"'
# ============================================================
- name : remove tags with default purge_tags=true (expected changed=true) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
az : "{{ aws_region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
AnotherTag : SomeValue
<< : *aws_connection_info
state : present
check_mode : true
register : vpc_subnet_remove_tags
- name : assert tag removal happened (expected changed=true)
assert:
that:
- 'vpc_subnet_remove_tags.changed'
- name : remove tags with default purge_tags=true (expected changed=true)
- name : remove tags with default purge_tags=true (expected changed=true)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
az : "{{ ec2_region }}a"
az : "{{ aws _region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
tags:
AnotherTag : SomeValue
AnotherTag : SomeValue
region : '{{ ec2_region }}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
register : vpc_subnet_remove_tags
register : vpc_subnet_remove_tags
@ -138,18 +244,35 @@
- '"Description" not in vpc_subnet_remove_tags.subnet.tags'
- '"Description" not in vpc_subnet_remove_tags.subnet.tags'
- '"AnotherTag" in vpc_subnet_remove_tags.subnet.tags and vpc_subnet_remove_tags.subnet.tags["AnotherTag"] == "SomeValue"'
- '"AnotherTag" in vpc_subnet_remove_tags.subnet.tags and vpc_subnet_remove_tags.subnet.tags["AnotherTag"] == "SomeValue"'
# ============================================================
- name : change tags with purge_tags=false (expected changed=true) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
az : "{{ aws_region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
<< : *aws_connection_info
state : present
purge_tags : false
check_mode : true
register : vpc_subnet_change_tags
- name : assert tag addition happened (expected changed=true)
assert:
that:
- 'vpc_subnet_change_tags.changed'
- name : change tags with purge_tags=false (expected changed=true)
- name : change tags with purge_tags=false (expected changed=true)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
az : "{{ ec2_region }}a"
az : "{{ aws _region }}a"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
tags:
tags:
Name : '{{ec2_vpc_subnet_name}}'
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
Description : '{{ec2_vpc_subnet_description}}'
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
purge_tags : false
purge_tags : false
register : vpc_subnet_change_tags
register : vpc_subnet_change_tags
@ -162,15 +285,27 @@
- '"Description" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["Description"] == ec2_vpc_subnet_description'
- '"Description" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["Description"] == ec2_vpc_subnet_description'
- '"AnotherTag" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["AnotherTag"] == "SomeValue"'
- '"AnotherTag" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["AnotherTag"] == "SomeValue"'
# ============================================================
- name : test state=absent (expected changed=true) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : absent
<< : *aws_connection_info
check_mode : true
register : result
- name : assert state=absent (expected changed=true)
assert:
that:
- 'result.changed'
- name : test state=absent (expected changed=true)
- name : test state=absent (expected changed=true)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
state : absent
state : absent
region : '{{ ec2_region }}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
register : result
register : result
- name : assert state=absent (expected changed=true)
- name : assert state=absent (expected changed=true)
@ -178,15 +313,55 @@
that:
that:
- 'result.changed'
- 'result.changed'
# ============================================================
- name : test state=absent (expected changed=false) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : absent
<< : *aws_connection_info
check_mode : true
register : result
- name : assert state=absent (expected changed=false)
assert:
that:
- 'not result.changed'
- name : test state=absent (expected changed=false)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : absent
<< : *aws_connection_info
register : result
- name : assert state=absent (expected changed=false)
assert:
that:
- 'not result.changed'
# ============================================================
- name : create subnet without AZ (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : present
<< : *aws_connection_info
check_mode : true
register : subnet_without_az
- name : check that subnet without AZ works fine
assert:
that:
- 'subnet_without_az.changed'
- name : create subnet without AZ
- name : create subnet without AZ
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
state : present
state : present
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
register : subnet_without_az
register : subnet_without_az
- name : check that subnet without AZ works fine
- name : check that subnet without AZ works fine
@ -194,15 +369,27 @@
that:
that:
- 'subnet_without_az.changed'
- 'subnet_without_az.changed'
# ============================================================
- name : remove subnet without AZ (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : absent
<< : *aws_connection_info
check_mode : true
register : result
- name : assert state=absent (expected changed=true)
assert:
that:
- 'result.changed'
- name : remove subnet without AZ
- name : remove subnet without AZ
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
state : absent
state : absent
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
register : result
register : result
- name : assert state=absent (expected changed=true)
- name : assert state=absent (expected changed=true)
@ -210,6 +397,7 @@
that:
that:
- 'result.changed'
- 'result.changed'
# ============================================================
# FIXME - Replace by creating IPv6 enabled VPC once ec2_vpc_net module supports it.
# FIXME - Replace by creating IPv6 enabled VPC once ec2_vpc_net module supports it.
- name : install aws cli - FIXME temporary this should go for a lighterweight solution
- name : install aws cli - FIXME temporary this should go for a lighterweight solution
command : pip install awscli
command : pip install awscli
@ -220,7 +408,10 @@
AWS_ACCESS_KEY_ID : '{{aws_access_key}}'
AWS_ACCESS_KEY_ID : '{{aws_access_key}}'
AWS_SECRET_ACCESS_KEY : '{{aws_secret_key}}'
AWS_SECRET_ACCESS_KEY : '{{aws_secret_key}}'
AWS_SESSION_TOKEN : '{{security_token}}'
AWS_SESSION_TOKEN : '{{security_token}}'
AWS_DEFAULT_REGION : '{{ec2_region}}'
AWS_DEFAULT_REGION : '{{aws_region}}'
- name : wait for the IPv6 CIDR to be assigned
command : sleep 5
- name : Get the assigned IPv6 CIDR
- name : Get the assigned IPv6 CIDR
command : aws ec2 describe-vpcs --vpc-ids '{{ vpc_result.vpc.id }}'
command : aws ec2 describe-vpcs --vpc-ids '{{ vpc_result.vpc.id }}'
@ -228,12 +419,32 @@
AWS_ACCESS_KEY_ID : '{{aws_access_key}}'
AWS_ACCESS_KEY_ID : '{{aws_access_key}}'
AWS_SECRET_ACCESS_KEY : '{{aws_secret_key}}'
AWS_SECRET_ACCESS_KEY : '{{aws_secret_key}}'
AWS_SESSION_TOKEN : '{{security_token}}'
AWS_SESSION_TOKEN : '{{security_token}}'
AWS_DEFAULT_REGION : '{{ ec2 _region}}'
AWS_DEFAULT_REGION : '{{ aws _region}}'
register : vpc_ipv6
register : vpc_ipv6
- set_fact:
- set_fact:
vpc_ipv6_cidr : "{{ vpc_ipv6.stdout | from_json | json_query('Vpcs[0].Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock') }}"
vpc_ipv6_cidr : "{{ vpc_ipv6.stdout | from_json | json_query('Vpcs[0].Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock') }}"
# ============================================================
- name : create subnet with IPv6 (expected changed=true) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
assign_instances_ipv6 : true
state : present
<< : *aws_connection_info
tags:
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
check_mode : true
register : vpc_subnet_ipv6_create
- name : assert creation with IPv6 happened (expected changed=true)
assert:
that:
- 'vpc_subnet_ipv6_create.changed'
- name : create subnet with IPv6 (expected changed=true)
- name : create subnet with IPv6 (expected changed=true)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
@ -241,10 +452,7 @@
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
assign_instances_ipv6 : true
assign_instances_ipv6 : true
state : present
state : present
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
tags:
tags:
Name : '{{ec2_vpc_subnet_name}}'
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
Description : '{{ec2_vpc_subnet_description}}'
@ -260,16 +468,33 @@
- '"Description" in vpc_subnet_ipv6_create.subnet.tags and vpc_subnet_ipv6_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
- '"Description" in vpc_subnet_ipv6_create.subnet.tags and vpc_subnet_ipv6_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
- 'vpc_subnet_ipv6_create.subnet.assign_ipv6_address_on_creation'
- 'vpc_subnet_ipv6_create.subnet.assign_ipv6_address_on_creation'
# ============================================================
- name : recreate subnet (expected changed=false) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
assign_instances_ipv6 : true
<< : *aws_connection_info
state : present
tags:
Name : '{{ec2_vpc_subnet_name}}'
Description : '{{ec2_vpc_subnet_description}}'
check_mode : true
register : vpc_subnet_ipv6_recreate
- name : assert recreation changed nothing (expected changed=false)
assert:
that:
- 'not vpc_subnet_ipv6_recreate.changed'
- name : recreate subnet (expected changed=false)
- name : recreate subnet (expected changed=false)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
assign_instances_ipv6 : true
assign_instances_ipv6 : true
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
tags:
tags:
Name : '{{ec2_vpc_subnet_name}}'
Name : '{{ec2_vpc_subnet_name}}'
@ -282,16 +507,31 @@
- 'not vpc_subnet_ipv6_recreate.changed'
- 'not vpc_subnet_ipv6_recreate.changed'
- 'vpc_subnet_ipv6_recreate.subnet == vpc_subnet_ipv6_create.subnet'
- 'vpc_subnet_ipv6_recreate.subnet == vpc_subnet_ipv6_create.subnet'
# ============================================================
- name : change subnet ipv6 attribute (expected changed=true) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
assign_instances_ipv6 : false
<< : *aws_connection_info
state : present
purge_tags : false
check_mode : true
register : vpc_change_attribute
- name : assert assign_instances_ipv6 attribute changed (expected changed=true)
assert:
that:
- 'vpc_change_attribute.changed'
- name : change subnet ipv6 attribute (expected changed=true)
- name : change subnet ipv6 attribute (expected changed=true)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
assign_instances_ipv6 : false
assign_instances_ipv6 : false
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
purge_tags : false
purge_tags : false
register : vpc_change_attribute
register : vpc_change_attribute
@ -302,15 +542,13 @@
- 'vpc_change_attribute.changed'
- 'vpc_change_attribute.changed'
- 'not vpc_change_attribute.subnet.assign_ipv6_address_on_creation'
- 'not vpc_change_attribute.subnet.assign_ipv6_address_on_creation'
# ============================================================
- name : add second subnet with duplicate ipv6 cidr (expected failure)
- name : add second subnet with duplicate ipv6 cidr (expected failure)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.144/28"
cidr : "10.232.232.144/28"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
ipv6_cidr : "{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}"
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
purge_tags : false
purge_tags : false
register : vpc_add_duplicate_ipv6
register : vpc_add_duplicate_ipv6
@ -322,14 +560,27 @@
- 'vpc_add_duplicate_ipv6.failed'
- 'vpc_add_duplicate_ipv6.failed'
- "'The IPv6 CIDR \\'{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}\\' conflicts with another subnet' in vpc_add_duplicate_ipv6.msg"
- "'The IPv6 CIDR \\'{{ vpc_ipv6_cidr | regex_replace('::/56', '::/64') }}\\' conflicts with another subnet' in vpc_add_duplicate_ipv6.msg"
# ============================================================
- name : remove subnet ipv6 cidr (expected changed=true) (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
<< : *aws_connection_info
state : present
purge_tags : false
check_mode : true
register : vpc_remove_ipv6_cidr
- name : assert subnet ipv6 cidr removed (expected changed=true)
assert:
that:
- 'vpc_remove_ipv6_cidr.changed'
- name : remove subnet ipv6 cidr (expected changed=true)
- name : remove subnet ipv6 cidr (expected changed=true)
ec2_vpc_subnet:
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
region : '{{ec2_region}}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
state : present
state : present
purge_tags : false
purge_tags : false
register : vpc_remove_ipv6_cidr
register : vpc_remove_ipv6_cidr
@ -341,6 +592,75 @@
- "vpc_remove_ipv6_cidr.subnet.ipv6_cidr_block == ''"
- "vpc_remove_ipv6_cidr.subnet.ipv6_cidr_block == ''"
- 'not vpc_remove_ipv6_cidr.subnet.assign_ipv6_address_on_creation'
- 'not vpc_remove_ipv6_cidr.subnet.assign_ipv6_address_on_creation'
# ============================================================
- name : test adding a tag that looks like a boolean to the subnet (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : present
purge_tags : false
tags:
looks_like_boolean : true
<< : *aws_connection_info
check_mode : true
register : vpc_subnet_info
- name : assert a tag was added
assert:
that:
- 'vpc_subnet_info.changed'
- name : test adding a tag that looks like a boolean to the subnet
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : present
purge_tags : false
tags:
looks_like_boolean : true
<< : *aws_connection_info
register : vpc_subnet_info
- name : assert a tag was added
assert:
that:
- 'vpc_subnet_info.changed'
- 'vpc_subnet_info.subnet.tags.looks_like_boolean == "True"'
# ============================================================
- name : test idempotence adding a tag that looks like a boolean (CHECK MODE)
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : present
purge_tags : false
tags:
looks_like_boolean : true
<< : *aws_connection_info
check_mode : true
register : vpc_subnet_info
- name : assert a tag was added
assert:
that:
- 'not vpc_subnet_info.changed'
- name : test idempotence adding a tag that looks like a boolean
ec2_vpc_subnet:
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
state : present
purge_tags : false
tags:
looks_like_boolean : true
<< : *aws_connection_info
register : vpc_subnet_info
- name : assert a tag was added
assert:
that:
- 'not vpc_subnet_info.changed'
always:
always:
################################################
################################################
@ -352,17 +672,11 @@
cidr : "10.232.232.128/28"
cidr : "10.232.232.128/28"
vpc_id : "{{ vpc_result.vpc.id }}"
vpc_id : "{{ vpc_result.vpc.id }}"
state : absent
state : absent
region : '{{ ec2_region }}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'
- name : tidy up VPC
- name : tidy up VPC
ec2_vpc_net:
ec2_vpc_net:
name : "{{ resource_prefix }}-vpc"
name : "{{ resource_prefix }}-vpc"
state : absent
state : absent
cidr_block : "10.232.232.128/26"
cidr_block : "10.232.232.128/26"
region : '{{ ec2_region }}'
<< : *aws_connection_info
aws_access_key : '{{ aws_access_key }}'
aws_secret_key : '{{ aws_secret_key }}'
security_token : '{{ security_token }}'