mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Support check_mode in ec2_vpc_nacl (#23112)
* Support check_mode in ec2_vpc_nacl Ensure that all API calls that make changes are guarded by `if not module.check_mode`. * Update ec2_vpc_nacl_facts to latest pep8 standards
This commit is contained in:
parent
42d57782c0
commit
84eea2a7e3
3 changed files with 36 additions and 26 deletions
|
@ -103,17 +103,21 @@ nacl:
|
|||
type: list of list
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import ec2_argument_spec, boto3_conn, get_aws_connection_info
|
||||
from ansible.module_utils.ec2 import ansible_dict_to_boto3_filter_list, HAS_BOTO3
|
||||
from ansible.module_utils.ec2 import camel_dict_to_snake_dict, boto3_tag_list_to_ansible_dict
|
||||
|
||||
try:
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError, NoCredentialsError
|
||||
HAS_BOTO3 = True
|
||||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
pass # caught by imported HAS_BOTO3
|
||||
|
||||
# VPC-supported IANA protocol numbers
|
||||
# http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
|
||||
PROTOCOL_NAMES = {'-1': 'all', '1': 'icmp', '6': 'tcp', '17': 'udp'}
|
||||
|
||||
|
||||
def list_ec2_vpc_nacls(connection, module):
|
||||
|
||||
nacl_ids = module.params.get("nacl_ids")
|
||||
|
@ -134,10 +138,10 @@ def list_ec2_vpc_nacls(connection, module):
|
|||
if 'tags' in nacl:
|
||||
nacl['tags'] = boto3_tag_list_to_ansible_dict(nacl['tags'], 'key', 'value')
|
||||
if 'entries' in nacl:
|
||||
nacl['egress'] = [nacl_entry_to_list(e) for e in nacl['entries']
|
||||
if e['rule_number'] != 32767 and e['egress']]
|
||||
nacl['ingress'] = [nacl_entry_to_list(e) for e in nacl['entries']
|
||||
if e['rule_number'] != 32767 and not e['egress']]
|
||||
nacl['egress'] = [nacl_entry_to_list(entry) for entry in nacl['entries']
|
||||
if entry['rule_number'] != 32767 and entry['egress']]
|
||||
nacl['ingress'] = [nacl_entry_to_list(e) for entry in nacl['entries']
|
||||
if entry['rule_number'] != 32767 and not entry['egress']]
|
||||
del nacl['entries']
|
||||
if 'associations' in nacl:
|
||||
nacl['subnets'] = [a['subnet_id'] for a in nacl['associations']]
|
||||
|
@ -148,6 +152,7 @@ def list_ec2_vpc_nacls(connection, module):
|
|||
|
||||
module.exit_json(nacls=snaked_nacls)
|
||||
|
||||
|
||||
def nacl_entry_to_list(entry):
|
||||
|
||||
elist = [entry['rule_number'],
|
||||
|
@ -170,6 +175,7 @@ def nacl_entry_to_list(entry):
|
|||
|
||||
return elist
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
argument_spec = ec2_argument_spec()
|
||||
|
@ -181,10 +187,7 @@ def main():
|
|||
)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
mutually_exclusive=[
|
||||
['nacl_ids', 'filters']
|
||||
]
|
||||
)
|
||||
mutually_exclusive=[['nacl_ids', 'filters']])
|
||||
|
||||
if not HAS_BOTO3:
|
||||
module.fail_json(msg='boto3 required for this module')
|
||||
|
@ -199,8 +202,5 @@ def main():
|
|||
|
||||
list_ec2_vpc_nacls(connection, module)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue