meraki_content_filtering - Enable check mode (#54638)
* Add support for check mode. * Add diff support - Need to analyze diff for accuracy - Updated check mode changed value * Improve test coverage * Remove a duplicate integration test
This commit is contained in:
parent
6da2d40500
commit
72f2d05b6f
3 changed files with 94 additions and 31 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- "meraki_content_filtering - Add support for check mode."
|
|
@ -120,6 +120,7 @@ import os
|
|||
from ansible.module_utils.basic import AnsibleModule, json, env_fallback
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.common.dict_transformations import recursive_diff
|
||||
from ansible.module_utils.network.meraki.meraki import MerakiModule, meraki_argument_spec
|
||||
|
||||
|
||||
|
@ -203,15 +204,26 @@ def main():
|
|||
current = meraki.request(path, method='GET')
|
||||
proposed = current.copy()
|
||||
proposed.update(payload)
|
||||
if meraki.is_update_required(current, payload) is True:
|
||||
meraki.result['diff'] = dict()
|
||||
diff = recursive_diff(current, payload)
|
||||
meraki.result['diff']['before'] = diff[0]
|
||||
meraki.result['diff']['after'] = diff[1]
|
||||
if module.check_mode:
|
||||
meraki.result['data'] = payload
|
||||
current.update(payload)
|
||||
meraki.result['changed'] = True
|
||||
meraki.result['data'] = current
|
||||
meraki.exit_json(**meraki.result)
|
||||
if meraki.is_update_required(current, payload):
|
||||
response = meraki.request(path, method='PUT', payload=json.dumps(payload))
|
||||
meraki.result['data'] = response
|
||||
meraki.result['changed'] = True
|
||||
else:
|
||||
meraki.result['data'] = current
|
||||
if module.check_mode:
|
||||
meraki.result['data'] = current
|
||||
meraki.exit_json(**meraki.result)
|
||||
meraki.result['data'] = current
|
||||
meraki.exit_json(**meraki.result)
|
||||
|
||||
# in the event of a successful module execution, you will want to
|
||||
# simple AnsibleModule.exit_json(), passing the key/value results
|
||||
|
|
|
@ -9,23 +9,7 @@
|
|||
msg: Please define an API key
|
||||
when: auth_key is not defined
|
||||
|
||||
- name: Use an invalid domain
|
||||
meraki_config_template:
|
||||
auth_key: '{{ auth_key }}'
|
||||
host: marrrraki.com
|
||||
state: query
|
||||
org_name: DevTestOrg
|
||||
output_level: debug
|
||||
delegate_to: localhost
|
||||
register: invalid_domain
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Connection assertions
|
||||
assert:
|
||||
that:
|
||||
- '"Failed to connect to" in invalid_domain.msg'
|
||||
|
||||
- name: Create network with type switch
|
||||
- name: Create network
|
||||
meraki_network:
|
||||
auth_key: '{{ auth_key }}'
|
||||
state: present
|
||||
|
@ -36,6 +20,38 @@
|
|||
delegate_to: localhost
|
||||
register: create_net_appliance
|
||||
|
||||
- name: Test net_name and id exclusivity
|
||||
meraki_content_filtering:
|
||||
auth_key: '{{auth_key}}'
|
||||
org_name: '{{test_org_name}}'
|
||||
net_name: '{{test_net_name}}'
|
||||
net_id: 12345
|
||||
state: present
|
||||
allowed_urls:
|
||||
- "http://www.ansible.com/*"
|
||||
register: net_exclusive
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'net_exclusive.msg == "net_name and net_id are mutually exclusive"'
|
||||
|
||||
- name: Set single allowed URL pattern with check mode
|
||||
meraki_content_filtering:
|
||||
auth_key: '{{auth_key}}'
|
||||
org_name: '{{test_org_name}}'
|
||||
net_name: '{{test_net_name}}'
|
||||
state: present
|
||||
allowed_urls:
|
||||
- "http://www.ansible.com/*"
|
||||
register: single_allowed_check
|
||||
check_mode: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- single_allowed_check.data.allowedUrlPatterns | length == 1
|
||||
- single_allowed_check is changed
|
||||
|
||||
- name: Set single allowed URL pattern
|
||||
meraki_content_filtering:
|
||||
auth_key: '{{auth_key}}'
|
||||
|
@ -46,13 +62,28 @@
|
|||
- "http://www.ansible.com/*"
|
||||
register: single_allowed
|
||||
|
||||
- debug:
|
||||
var: single_allowed.data.allowedUrlPatterns
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- single_allowed.data.allowedUrlPatterns | length == 1
|
||||
|
||||
- name: Set single allowed URL pattern for idempotency with check mode
|
||||
meraki_content_filtering:
|
||||
auth_key: '{{auth_key}}'
|
||||
org_name: '{{test_org_name}}'
|
||||
net_name: '{{test_net_name}}'
|
||||
state: present
|
||||
allowed_urls:
|
||||
- "http://www.ansible.com/*"
|
||||
register: single_allowed_idempotent_check
|
||||
check_mode: yes
|
||||
|
||||
- debug:
|
||||
var: single_allowed_idempotent_check
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- single_allowed_idempotent_check is not changed
|
||||
|
||||
- name: Set single allowed URL pattern for idempotency
|
||||
meraki_content_filtering:
|
||||
auth_key: '{{auth_key}}'
|
||||
|
@ -116,16 +147,36 @@
|
|||
category_list_size: full list
|
||||
blocked_categories:
|
||||
- "Adult and Pornography"
|
||||
register: blocked_cateogry
|
||||
register: blocked_category
|
||||
|
||||
- debug:
|
||||
var: blocked_cateogry
|
||||
var: blocked_category
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- blocked_cateogry.changed == True
|
||||
- blocked_cateogry.data.blockedUrlCategories | length == 1
|
||||
- blocked_cateogry.data.urlCategoryListSize == "fullList"
|
||||
- blocked_category.changed == True
|
||||
- blocked_category.data.blockedUrlCategories | length == 1
|
||||
- blocked_category.data.urlCategoryListSize == "fullList"
|
||||
|
||||
- name: Set blocked URL category with top sites
|
||||
meraki_content_filtering:
|
||||
auth_key: '{{auth_key}}'
|
||||
org_name: '{{test_org_name}}'
|
||||
net_name: '{{test_net_name}}'
|
||||
state: present
|
||||
category_list_size: top sites
|
||||
blocked_categories:
|
||||
- "Adult and Pornography"
|
||||
register: blocked_category
|
||||
|
||||
- debug:
|
||||
var: blocked_category
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- blocked_category.changed == True
|
||||
- blocked_category.data.blockedUrlCategories | length == 1
|
||||
- blocked_category.data.urlCategoryListSize == "topSites"
|
||||
|
||||
always:
|
||||
- name: Reset policies
|
||||
|
@ -139,5 +190,3 @@
|
|||
-
|
||||
blocked_urls:
|
||||
-
|
||||
# blocked_categories:
|
||||
# -
|
||||
|
|
Loading…
Reference in a new issue