@ -146,7 +146,8 @@ def update_vpc_tags(vpc, module, vpc_obj, tags, name):
try :
try :
current_tags = dict ( ( t . name , t . value ) for t in vpc . get_all_tags ( filters = { ' resource-id ' : vpc_obj . id } ) )
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 ) :
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
return True
else :
else :
return False
return False
@ -158,7 +159,8 @@ def update_vpc_tags(vpc, module, vpc_obj, tags, name):
def update_dhcp_opts ( connection , module , vpc_obj , dhcp_id ) :
def update_dhcp_opts ( connection , module , vpc_obj , dhcp_id ) :
if vpc_obj . dhcp_options_id != 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
return True
else :
else :
return False
return False
@ -194,6 +196,7 @@ def main():
module = AnsibleModule (
module = AnsibleModule (
argument_spec = argument_spec ,
argument_spec = argument_spec ,
supports_check_mode = True
)
)
if not HAS_BOTO :
if not HAS_BOTO :
@ -231,8 +234,11 @@ def main():
if vpc_obj is None :
if vpc_obj is None :
try :
try :
vpc_obj = connection . create_vpc ( cidr_block , instance_tenancy = tenancy )
changed = True
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 :
except BotoServerError as e :
module . fail_json ( msg = e )
module . fail_json ( msg = e )
@ -254,18 +260,20 @@ def main():
# which is needed in order to detect the current status of DNS options. For now we just update
# 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.
# the attribute each time and is not used as a changed-factor.
try :
try :
connection . modify_vpc_attribute ( vpc_obj . id , enable_dns_support = dns_support )
if not module . check_mode :
connection . modify_vpc_attribute ( vpc_obj . id , enable_dns_hostnames = dns_hostnames )
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 :
except BotoServerError as e :
e_msg = boto_exception ( e )
e_msg = boto_exception ( e )
module . fail_json ( msg = e_msg )
module . fail_json ( msg = e_msg )
# get the vpc obj again in case it has changed
if not module . check_mode :
try :
# get the vpc obj again in case it has changed
vpc_obj = connection . get_all_vpcs ( vpc_obj . id ) [ 0 ]
try :
except BotoServerError as e :
vpc_obj = connection . get_all_vpcs ( vpc_obj . id ) [ 0 ]
e_msg = boto_exception ( e )
except BotoServerError as e :
module . fail_json ( msg = e_msg )
e_msg = boto_exception ( e )
module . fail_json ( msg = e_msg )
module . exit_json ( changed = changed , vpc = get_vpc_values ( vpc_obj ) )
module . exit_json ( changed = changed , vpc = get_vpc_values ( vpc_obj ) )
@ -276,7 +284,8 @@ def main():
if vpc_obj is not None :
if vpc_obj is not None :
try :
try :
connection . delete_vpc ( vpc_obj . id )
if not module . check_mode :
connection . delete_vpc ( vpc_obj . id )
vpc_obj = None
vpc_obj = None
changed = True
changed = True
except BotoServerError as e :
except BotoServerError as e :