meraki_content_filtering - Add support for querying (#57273)

* Added querying functionality

* Fix PEP8 and documentation

* Increment version added

* Fix version info
This commit is contained in:
Kevin Breit 2019-06-18 04:22:46 -05:00 committed by Sumit Jaiswal
parent a66687f2d2
commit d24e9ab4bb
2 changed files with 79 additions and 3 deletions

View file

@ -46,7 +46,7 @@ options:
state:
description:
- States that a policy should be created or modified.
choices: [present]
choices: [present, query]
default: present
type: str
allowed_urls:
@ -67,7 +67,12 @@ options:
- Determines whether a network filters fo rall URLs in a category or only the list of top blocked sites.
choices: [ top sites, full list ]
type: str
subset:
description:
- Display only certain facts.
choices: [categories, policy]
type: str
version_added: '2.9'
author:
- Kevin Breit (@kbreit)
extends_documentation_fragment: meraki
@ -140,11 +145,12 @@ def main():
argument_spec.update(
net_id=dict(type='str'),
net_name=dict(type='str', aliases=['network']),
state=dict(type='str', default='present', choices=['present']),
state=dict(type='str', default='present', choices=['present', 'query']),
allowed_urls=dict(type='list'),
blocked_urls=dict(type='list'),
blocked_categories=dict(type='list'),
category_list_size=dict(type='str', choices=['top sites', 'full list']),
subset=dict(type='str', choices=['categories', 'policy']),
)
# the AnsibleModule object will be our abstraction working with Ansible
@ -178,6 +184,22 @@ def main():
nets = meraki.get_nets(org_id=org_id)
net_id = meraki.get_net_id(org_id, meraki.params['net_name'], data=nets)
if meraki.params['state'] == 'query':
if meraki.params['subset']:
if meraki.params['subset'] == 'categories':
path = meraki.construct_path('categories', net_id=net_id)
elif meraki.params['subset'] == 'policy':
path = meraki.construct_path('policy', net_id=net_id)
meraki.result['data'] = meraki.request(path, method='GET')
else:
response_data = {'categories': None,
'policy': None,
}
path = meraki.construct_path('categories', net_id=net_id)
response_data['categories'] = meraki.request(path, method='GET')
path = meraki.construct_path('policy', net_id=net_id)
response_data['policy'] = meraki.request(path, method='GET')
meraki.result['data'] = response_data
if module.params['state'] == 'present':
payload = dict()
if meraki.params['allowed_urls']:

View file

@ -179,6 +179,60 @@
- blocked_category.data.blocked_url_categories | length == 1
- blocked_category.data.url_category_list_size == "topSites"
- name: Query all content filtering information
meraki_content_filtering:
auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}'
state: query
delegate_to: localhost
register: query_all
- debug:
var: query_all
- name: Query all content filtering assertion
assert:
that:
- query_all.data.categories is defined
- query_all.data.policy is defined
- name: Query categories
meraki_content_filtering:
auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}'
state: query
subset: categories
delegate_to: localhost
register: query_categories
- debug:
var: query_categories
- name: Query categories assertion
assert:
that:
- query_categories.data is defined
- name: Query content filtering policies
meraki_content_filtering:
auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}'
subset: policy
state: query
delegate_to: localhost
register: query_policy
- debug:
var: query_policy
- name: Query contnet filtering policy assertion
assert:
that:
- query_policy.data is defined
always:
- name: Reset policies
meraki_content_filtering: