mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-23 06:21:43 -07:00
Indented code so it only executes tag comparison for matching cird values
This commit is contained in:
parent
db14b544a5
commit
2fa3f16012
1 changed files with 29 additions and 28 deletions
|
@ -413,30 +413,31 @@ def create_vpc(module, vpc_conn):
|
||||||
if subnet['cidr'] == csn.cidr_block:
|
if subnet['cidr'] == csn.cidr_block:
|
||||||
add_subnet = False
|
add_subnet = False
|
||||||
|
|
||||||
# Check if AWS subnet tags are in playbook subnet tags
|
# Check if AWS subnet tags are in playbook subnet tags
|
||||||
subnet_tags_extra = (set(csn.tags.items()).issubset(set(new_subnet_tags.items())))
|
existing_tags_subset_of_new_tags = (set(csn.tags.items()).issubset(set(new_subnet_tags.items())))
|
||||||
# Check if subnet tags in playbook are in AWS subnet tags
|
# Check if subnet tags in playbook are in AWS subnet tags
|
||||||
subnet_tags_current = (set(new_subnet_tags.items()).issubset(set(csn.tags.items())))
|
new_tags_subset_of_existing_tags = (set(new_subnet_tags.items()).issubset(set(csn.tags.items())))
|
||||||
if subnet_tags_extra is False:
|
|
||||||
try:
|
|
||||||
for item in csn.tags.items():
|
|
||||||
if item not in new_subnet_tags.items():
|
|
||||||
subnet_tags_delete.append(item)
|
|
||||||
|
|
||||||
subnet_tags_delete = [key[0] for key in subnet_tags_delete]
|
if existing_tags_subset_of_new_tags is False:
|
||||||
delete_subnet_tag = vpc_conn.delete_tags(csn.id, subnet_tags_delete)
|
try:
|
||||||
changed = True
|
for item in csn.tags.items():
|
||||||
except EC2ResponseError, e:
|
if item not in new_subnet_tags.items():
|
||||||
module.fail_json(msg='Unable to delete resource tag, error {0}'.format(e))
|
subnet_tags_delete.append(item)
|
||||||
# Add new subnet tags if not current
|
|
||||||
subnet_tags_current = (set(new_subnet_tags.items()).issubset(set(csn.tags.items())))
|
|
||||||
if subnet_tags_current is not True:
|
|
||||||
try:
|
|
||||||
changed = True
|
|
||||||
create_subnet_tag = vpc_conn.create_tags(csn.id, new_subnet_tags)
|
|
||||||
|
|
||||||
except EC2ResponseError, e:
|
subnet_tags_delete = [key[0] for key in subnet_tags_delete]
|
||||||
module.fail_json(msg='Unable to create resource tag, error: {0}'.format(e))
|
delete_subnet_tag = vpc_conn.delete_tags(csn.id, subnet_tags_delete)
|
||||||
|
changed = True
|
||||||
|
except EC2ResponseError, e:
|
||||||
|
module.fail_json(msg='Unable to delete resource tag, error {0}'.format(e))
|
||||||
|
# Add new subnet tags if not current
|
||||||
|
|
||||||
|
if new_tags_subset_of_existing_tags is False:
|
||||||
|
try:
|
||||||
|
changed = True
|
||||||
|
create_subnet_tag = vpc_conn.create_tags(csn.id, new_subnet_tags)
|
||||||
|
|
||||||
|
except EC2ResponseError, e:
|
||||||
|
module.fail_json(msg='Unable to create resource tag, error: {0}'.format(e))
|
||||||
|
|
||||||
if add_subnet:
|
if add_subnet:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue