amazon: extract copies of boto_exception to module_utils.ec2 (#20403)

* amazon: extract boto_exception to ec2 module

This function was copy/pasted throughout several Amazon modules. This
causes a consistency problem, since some improvements to message
formatting were applied to some modules but not others. Now all modules
use the same, improved function.

* Rebase and make requested changes

* Rebase and make requested changes
This commit is contained in:
David M. Lee 2017-08-23 10:40:32 -05:00 committed by Ryan Brown
commit 1d4ca0fd51
10 changed files with 36 additions and 92 deletions

View file

@ -352,6 +352,21 @@ Ansible format, this function will convert the keys to snake_case.
Converts a an Ansible list of filters to a boto3 friendly list of dicts. This is useful for any
boto3 `_facts` modules.
### boto_exception
Pass an exception returned from boto or boto3, and this function will consistently get the message from the exception.
```
import traceback
from ansible.module_utils.ec2 import boto_exception
try:
...
except boto.exception.BotoServerError as err:
error_msg = boto_exception(err)
module.fail_json(msg=error_msg, exception=traceback.format_exc())
```
#### boto3_tag_list_to_ansible_dict
Converts a boto3 tag list to an Ansible dict. Boto3 returns tags as a list of dicts containing keys