@@ -157,7 +157,8 @@ def wait_for_status(client, module, vpn_gateway_id, status):
157157 break
158158 else :
159159 time .sleep (polling_increment_secs )
160- except botocore .exceptions .ClientError as e :
160+ except botocore .exceptions .ClientError :
161+ e = get_exception ()
161162 module .fail_json (msg = str (e ))
162163
163164 result = response
@@ -170,7 +171,8 @@ def attach_vgw(client, module, vpn_gateway_id):
170171
171172 try :
172173 response = client .attach_vpn_gateway (VpnGatewayId = vpn_gateway_id , VpcId = params ['VpcId' ])
173- except botocore .exceptions .ClientError as e :
174+ except botocore .exceptions .ClientError :
175+ e = get_exception ()
174176 module .fail_json (msg = str (e ))
175177
176178 status_achieved , vgw = wait_for_status (client , module , [vpn_gateway_id ], 'attached' )
@@ -188,12 +190,14 @@ def detach_vgw(client, module, vpn_gateway_id, vpc_id=None):
188190 if vpc_id :
189191 try :
190192 response = client .detach_vpn_gateway (VpnGatewayId = vpn_gateway_id , VpcId = vpc_id )
191- except botocore .exceptions .ClientError as e :
193+ except botocore .exceptions .ClientError :
194+ e = get_exception ()
192195 module .fail_json (msg = str (e ))
193196 else :
194197 try :
195198 response = client .detach_vpn_gateway (VpnGatewayId = vpn_gateway_id , VpcId = params ['VpcId' ])
196- except botocore .exceptions .ClientError as e :
199+ except botocore .exceptions .ClientError :
200+ e = get_exception ()
197201 module .fail_json (msg = str (e ))
198202
199203 status_achieved , vgw = wait_for_status (client , module , [vpn_gateway_id ], 'detached' )
@@ -210,7 +214,8 @@ def create_vgw(client, module):
210214
211215 try :
212216 response = client .create_vpn_gateway (Type = params ['Type' ])
213- except botocore .exceptions .ClientError as e :
217+ except botocore .exceptions .ClientError :
218+ e = get_exception ()
214219 module .fail_json (msg = str (e ))
215220
216221 result = response
@@ -221,7 +226,8 @@ def delete_vgw(client, module, vpn_gateway_id):
221226
222227 try :
223228 response = client .delete_vpn_gateway (VpnGatewayId = vpn_gateway_id )
224- except botocore .exceptions .ClientError as e :
229+ except botocore .exceptions .ClientError :
230+ e = get_exception ()
225231 module .fail_json (msg = str (e ))
226232
227233 #return the deleted VpnGatewayId as this is not included in the above response
@@ -234,7 +240,8 @@ def create_tags(client, module, vpn_gateway_id):
234240
235241 try :
236242 response = client .create_tags (Resources = [vpn_gateway_id ],Tags = load_tags (module ))
237- except botocore .exceptions .ClientError as e :
243+ except botocore .exceptions .ClientError :
244+ e = get_exception ()
238245 module .fail_json (msg = str (e ))
239246
240247 result = response
@@ -247,12 +254,14 @@ def delete_tags(client, module, vpn_gateway_id, tags_to_delete=None):
247254 if tags_to_delete :
248255 try :
249256 response = client .delete_tags (Resources = [vpn_gateway_id ], Tags = tags_to_delete )
250- except botocore .exceptions .ClientError as e :
257+ except botocore .exceptions .ClientError :
258+ e = get_exception ()
251259 module .fail_json (msg = str (e ))
252260 else :
253261 try :
254262 response = client .delete_tags (Resources = [vpn_gateway_id ])
255- except botocore .exceptions .ClientError as e :
263+ except botocore .exceptions .ClientError :
264+ e = get_exception ()
256265 module .fail_json (msg = str (e ))
257266
258267 result = response
@@ -278,7 +287,8 @@ def find_tags(client, module, resource_id=None):
278287 response = client .describe_tags (Filters = [
279288 {'Name' : 'resource-id' , 'Values' : [resource_id ]}
280289 ])
281- except botocore .exceptions .ClientError as e :
290+ except botocore .exceptions .ClientError :
291+ e = get_exception ()
282292 module .fail_json (msg = str (e ))
283293
284294 result = response
@@ -325,7 +335,8 @@ def find_vpc(client, module):
325335 if params ['vpc_id' ]:
326336 try :
327337 response = client .describe_vpcs (VpcIds = [params ['vpc_id' ]])
328- except botocore .exceptions .ClientError as e :
338+ except botocore .exceptions .ClientError :
339+ e = get_exception ()
329340 module .fail_json (msg = str (e ))
330341
331342 result = response
@@ -344,14 +355,16 @@ def find_vgw(client, module, vpn_gateway_id=None):
344355 {'Name' : 'type' , 'Values' : [params ['Type' ]]},
345356 {'Name' : 'tag:Name' , 'Values' : [params ['Name' ]]}
346357 ])
347- except botocore .exceptions .ClientError as e :
358+ except botocore .exceptions .ClientError :
359+ e = get_exception ()
348360 module .fail_json (msg = str (e ))
349361
350362 else :
351363 if vpn_gateway_id :
352364 try :
353365 response = client .describe_vpn_gateways (VpnGatewayIds = vpn_gateway_id )
354- except botocore .exceptions .ClientError as e :
366+ except botocore .exceptions .ClientError :
367+ e = get_exception ()
355368 module .fail_json (msg = str (e ))
356369
357370 else :
@@ -360,7 +373,8 @@ def find_vgw(client, module, vpn_gateway_id=None):
360373 {'Name' : 'type' , 'Values' : [params ['Type' ]]},
361374 {'Name' : 'tag:Name' , 'Values' : [params ['Name' ]]}
362375 ])
363- except botocore .exceptions .ClientError as e :
376+ except botocore .exceptions .ClientError :
377+ e = get_exception ()
364378 module .fail_json (msg = str (e ))
365379
366380 result = response ['VpnGateways' ]
@@ -564,7 +578,8 @@ def main():
564578 try :
565579 region , ec2_url , aws_connect_kwargs = get_aws_connection_info (module , boto3 = True )
566580 client = boto3_conn (module , conn_type = 'client' , resource = 'ec2' , region = region , endpoint = ec2_url , ** aws_connect_kwargs )
567- except botocore .exceptions .NoCredentialsError , e :
581+ except botocore .exceptions .NoCredentialsError :
582+ e = get_exception ()
568583 module .fail_json (msg = "Can't authorize connection - " + str (e ))
569584
570585 if state == 'present' :
0 commit comments