Check mode fixes for ec2_vpc_net module (#2179)
* Check mode fixes for ec2_vpc_net module Returns VPC object information Detects state change for VPC, DHCP options, and tags in check mode * Early exit on VPC creation in check mode
This commit is contained in:
parent
0b95051039
commit
e9bf046c26
1 changed files with 21 additions and 12 deletions
|
@ -144,7 +144,8 @@ def update_vpc_tags(vpc, module, vpc_obj, tags, name):
|
|||
try:
|
||||
current_tags = dict((t.name, t.value) for t in vpc.get_all_tags(filters={'resource-id': vpc_obj.id}))
|
||||
if cmp(tags, current_tags):
|
||||
vpc.create_tags(vpc_obj.id, tags)
|
||||
if not module.check_mode:
|
||||
vpc.create_tags(vpc_obj.id, tags)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -156,7 +157,8 @@ def update_vpc_tags(vpc, module, vpc_obj, tags, name):
|
|||
def update_dhcp_opts(connection, module, vpc_obj, dhcp_id):
|
||||
|
||||
if vpc_obj.dhcp_options_id != dhcp_id:
|
||||
connection.associate_dhcp_options(dhcp_id, vpc_obj.id)
|
||||
if not module.check_mode:
|
||||
connection.associate_dhcp_options(dhcp_id, vpc_obj.id)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -192,6 +194,7 @@ def main():
|
|||
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
if not HAS_BOTO:
|
||||
|
@ -229,8 +232,11 @@ def main():
|
|||
|
||||
if vpc_obj is None:
|
||||
try:
|
||||
vpc_obj = connection.create_vpc(cidr_block, instance_tenancy=tenancy)
|
||||
changed = True
|
||||
if not module.check_mode:
|
||||
vpc_obj = connection.create_vpc(cidr_block, instance_tenancy=tenancy)
|
||||
else:
|
||||
module.exit_json(changed=changed)
|
||||
except BotoServerError as e:
|
||||
module.fail_json(msg=e)
|
||||
|
||||
|
@ -252,18 +258,20 @@ def main():
|
|||
# which is needed in order to detect the current status of DNS options. For now we just update
|
||||
# the attribute each time and is not used as a changed-factor.
|
||||
try:
|
||||
connection.modify_vpc_attribute(vpc_obj.id, enable_dns_support=dns_support)
|
||||
connection.modify_vpc_attribute(vpc_obj.id, enable_dns_hostnames=dns_hostnames)
|
||||
if not module.check_mode:
|
||||
connection.modify_vpc_attribute(vpc_obj.id, enable_dns_support=dns_support)
|
||||
connection.modify_vpc_attribute(vpc_obj.id, enable_dns_hostnames=dns_hostnames)
|
||||
except BotoServerError as e:
|
||||
e_msg=boto_exception(e)
|
||||
module.fail_json(msg=e_msg)
|
||||
|
||||
# get the vpc obj again in case it has changed
|
||||
try:
|
||||
vpc_obj = connection.get_all_vpcs(vpc_obj.id)[0]
|
||||
except BotoServerError as e:
|
||||
e_msg=boto_exception(e)
|
||||
module.fail_json(msg=e_msg)
|
||||
if not module.check_mode:
|
||||
# get the vpc obj again in case it has changed
|
||||
try:
|
||||
vpc_obj = connection.get_all_vpcs(vpc_obj.id)[0]
|
||||
except BotoServerError as e:
|
||||
e_msg=boto_exception(e)
|
||||
module.fail_json(msg=e_msg)
|
||||
|
||||
module.exit_json(changed=changed, vpc=get_vpc_values(vpc_obj))
|
||||
|
||||
|
@ -274,7 +282,8 @@ def main():
|
|||
|
||||
if vpc_obj is not None:
|
||||
try:
|
||||
connection.delete_vpc(vpc_obj.id)
|
||||
if not module.check_mode:
|
||||
connection.delete_vpc(vpc_obj.id)
|
||||
vpc_obj = None
|
||||
changed = True
|
||||
except BotoServerError as e:
|
||||
|
|
Loading…
Reference in a new issue