mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Fix python3, fix flake8, use common code
Update exception handling, remove use of iteritems Update for better flake8 compliance Use ansible_dict_to_boto3_filter_list rather than duplicating its implementation
This commit is contained in:
parent
2e35d5716b
commit
38ff9b735e
1 changed files with 16 additions and 26 deletions
|
@ -14,12 +14,19 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
# import module snippets
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.ec2 import ec2_argument_spec, get_aws_connection_info, boto3_conn
|
||||||
|
from ansible.module_utils.ec2 import ansible_dict_to_boto3_filter_list, HAS_BOTO3
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
module: ec2_vpc_nat_gateway_facts
|
module: ec2_vpc_nat_gateway_facts
|
||||||
short_description: Retrieves AWS VPC Managed Nat Gateway details using AWS methods.
|
short_description: Retrieves AWS VPC Managed Nat Gateway details using AWS methods.
|
||||||
description:
|
description:
|
||||||
- Gets various details related to AWS VPC Managed Nat Gateways
|
- Gets various details related to AWS VPC Managed Nat Gateways
|
||||||
version_added: "2.2"
|
version_added: "2.3"
|
||||||
requirements: [ boto3 ]
|
requirements: [ boto3 ]
|
||||||
options:
|
options:
|
||||||
nat_gateway_ids:
|
nat_gateway_ids:
|
||||||
|
@ -85,13 +92,8 @@ result:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import botocore
|
import botocore
|
||||||
import boto3
|
|
||||||
HAS_BOTO3 = True
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_BOTO3 = False
|
pass # will be detected by imported HAS_BOTO3
|
||||||
|
|
||||||
import time
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
def date_handler(obj):
|
def date_handler(obj):
|
||||||
|
@ -101,17 +103,7 @@ def date_handler(obj):
|
||||||
def get_nat_gateways(client, module, nat_gateway_id=None):
|
def get_nat_gateways(client, module, nat_gateway_id=None):
|
||||||
params = dict()
|
params = dict()
|
||||||
|
|
||||||
if module.params.get('filters'):
|
params['Filter'] = ansible_dict_to_boto3_filter_list(module.params.get('filters'))
|
||||||
params['Filter'] = []
|
|
||||||
for key, value in module.params.get('filters').iteritems():
|
|
||||||
temp_dict = dict()
|
|
||||||
temp_dict['Name'] = key
|
|
||||||
if isinstance(value, basestring):
|
|
||||||
temp_dict['Values'] = [value]
|
|
||||||
else:
|
|
||||||
temp_dict['Values'] = value
|
|
||||||
params['Filter'].append(temp_dict)
|
|
||||||
if module.params.get('nat_gateway_ids'):
|
|
||||||
params['NatGatewayIds'] = module.params.get('nat_gateway_ids')
|
params['NatGatewayIds'] = module.params.get('nat_gateway_ids')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -124,9 +116,10 @@ def get_nat_gateways(client, module, nat_gateway_id=None):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ec2_argument_spec()
|
argument_spec = ec2_argument_spec()
|
||||||
argument_spec.update(dict(
|
argument_spec.update(
|
||||||
filters=dict(default=None, type='dict'),
|
dict(
|
||||||
nat_gateway_ids=dict(default=None, type='list'),
|
filters=dict(default={}, type='dict'),
|
||||||
|
nat_gateway_ids=dict(default=[], type='list'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -142,16 +135,13 @@ def main():
|
||||||
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params)
|
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params)
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="region must be specified")
|
module.fail_json(msg="region must be specified")
|
||||||
except botocore.exceptions.NoCredentialsError, e:
|
except botocore.exceptions.NoCredentialsError as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
results = get_nat_gateways(connection, module)
|
results = get_nat_gateways(connection, module)
|
||||||
|
|
||||||
module.exit_json(result=results)
|
module.exit_json(result=results)
|
||||||
|
|
||||||
# import module snippets
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
from ansible.module_utils.ec2 import *
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue