1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

meraki_ssid - Modifying SSID won't work when specifying number (#51645)

* Fix bug when specifying SSID by number
- Migrated integration test to blocks with always
- Minor URL fixes

(cherry picked from commit ed79c294f2e3f82d4828226004c055dcd7ce9f63)

* Create changelog file

* Add new line
This commit is contained in:
Kevin Breit 2019-02-18 18:25:41 -06:00 committed by ansibot
parent 20ed819acd
commit 48128ec2fc
3 changed files with 245 additions and 243 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- meraki_ssid - Fix module to actually perform changes when state is present and SSID is referenced by number and not name.

View file

@ -375,8 +375,8 @@ def main():
meraki.params['follow_redirects'] = 'all' meraki.params['follow_redirects'] = 'all'
query_urls = {'ssid': '/networks/{net_id}/ssids'} query_urls = {'ssid': '/networks/{net_id}/ssids'}
query_url = {'ssid': 'networks/{net_id}/ssids/'} query_url = {'ssid': '/networks/{net_id}/ssids/'}
update_url = {'ssid': 'networks/{net_id}/ssids/'} update_url = {'ssid': '/networks/{net_id}/ssids/'}
meraki.url_catalog['get_all'].update(query_urls) meraki.url_catalog['get_all'].update(query_urls)
meraki.url_catalog['get_one'].update(query_url) meraki.url_catalog['get_one'].update(query_url)
@ -434,8 +434,10 @@ def main():
if meraki.params[v] is not None: if meraki.params[v] is not None:
payload[k] = meraki.params[v] payload[k] = meraki.params[v]
ssids = get_ssids(meraki, net_id) ssids = get_ssids(meraki, net_id)
original = ssids[get_ssid_number(meraki.params['name'], ssids)] number = meraki.params['number']
# meraki.fail_json(msg=meraki.is_update_required(original, payload), original=original, payload=payload) if number is None:
number = get_ssid_number(meraki.params['name'], ssids)
original = ssids[number]
if meraki.is_update_required(original, payload): if meraki.is_update_required(original, payload):
ssid_id = meraki.params['number'] ssid_id = meraki.params['number']
if ssid_id is None: # Name should be used to lookup number if ssid_id is None: # Name should be used to lookup number

View file

@ -3,280 +3,278 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
--- ---
- name: Test an API key is provided - block:
fail: - name: Test an API key is provided
msg: Please define an API key fail:
when: auth_key is not defined msg: Please define an API key
when: auth_key is not defined
- name: Use an invalid domain
meraki_organization: # - name: Use an invalid domain
auth_key: '{{ auth_key }}' # meraki_organization:
host: marrrraki.com # auth_key: '{{ auth_key }}'
state: present # host: marrrraki.com
org_name: IntTestOrg # state: present
output_level: debug # org_name: IntTestOrg
delegate_to: localhost # output_level: debug
register: invalid_domain # delegate_to: localhost
ignore_errors: yes # register: invalid_domain
# ignore_errors: yes
- name: Disable HTTP
meraki_organization: - name: Disable HTTP
auth_key: '{{ auth_key }}' meraki_organization:
use_https: false auth_key: '{{ auth_key }}'
state: query use_https: false
output_level: debug state: query
delegate_to: localhost output_level: debug
register: http delegate_to: localhost
ignore_errors: yes register: http
ignore_errors: yes
- name: Connection assertions - name: Connection assertions
assert: assert:
that: that:
- '"Failed to connect to" in invalid_domain.msg' # - '"Failed to connect to" in invalid_domain.msg'
- '"http" in http.url' - '"http" in http.url'
- name: Create test network - name: Create test network
meraki_network: meraki_network:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: TestNetSSID net_name: TestNetSSID
type: wireless type: wireless
register: test_net register: test_net
- debug: - debug:
msg: '{{test_net}}' msg: '{{test_net}}'
- name: Query all SSIDs - name: Query all SSIDs
meraki_ssid: meraki_ssid:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: query state: query
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: TestNetSSID net_name: TestNetSSID
delegate_to: localhost delegate_to: localhost
register: query_all register: query_all
- debug: - name: Enable and name SSID
msg: '{{query_all}}' meraki_ssid:
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
enabled: true
delegate_to: localhost
register: enable_name_ssid
- name: Enable and name SSID - debug:
meraki_ssid: msg: '{{ enable_name_ssid }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
enabled: true
delegate_to: localhost
register: enable_name_ssid
- debug: - assert:
msg: '{{ enable_name_ssid }}' that:
- query_all.data | length == 15
- query_all.data.0.name == 'TestNetSSID WiFi'
- enable_name_ssid.data.name == 'AnsibleSSID'
- assert: - name: Check for idempotency
that: meraki_ssid:
- query_all.data | length == 15 auth_key: '{{auth_key}}'
- query_all.data.0.name == 'TestNetSSID WiFi' state: present
- enable_name_ssid.data.name == 'AnsibleSSID' org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
enabled: true
delegate_to: localhost
register: enable_name_ssid_idempotent
- name: Check for idempotency - debug:
meraki_ssid: msg: '{{ enable_name_ssid_idempotent }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
enabled: true
delegate_to: localhost
register: enable_name_ssid_idempotent
- debug: - assert:
msg: '{{ enable_name_ssid_idempotent }}' that:
- enable_name_ssid_idempotent.changed == False
- assert: - name: Query one SSIDs
that: meraki_ssid:
- enable_name_ssid_idempotent.changed == False auth_key: '{{auth_key}}'
state: query
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
delegate_to: localhost
register: query_one
- name: Query one SSIDs - debug:
meraki_ssid: msg: '{{query_one}}'
auth_key: '{{auth_key}}'
state: query
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
delegate_to: localhost
register: query_one
- debug: - assert:
msg: '{{query_one}}' that:
- query_one.data.name == 'AnsibleSSID'
- assert: - name: Disable SSID without specifying number
that: meraki_ssid:
- query_one.data.name == 'AnsibleSSID' auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
enabled: false
delegate_to: localhost
register: disable_ssid
- name: Disable SSID without specifying number - debug:
meraki_ssid: msg: '{{ disable_ssid.data.enabled }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
enabled: false
delegate_to: localhost
register: disable_ssid
- debug: - assert:
msg: '{{ disable_ssid.data.enabled }}' that:
- disable_ssid.data.enabled == False
- assert: - name: Enable SSID with number
that: meraki_ssid:
- disable_ssid.data.enabled == False auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
number: 1
enabled: true
delegate_to: localhost
register: enable_ssid_number
- name: Enable SSID with number - debug:
meraki_ssid: msg: '{{ enable_ssid_number.data.enabled }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
number: 1
enabled: true
delegate_to: localhost
register: enable_ssid_number
- debug: - assert:
msg: '{{ enable_ssid_number.data.enabled }}' that:
- enable_ssid_number.data.enabled == True
- assert: - name: Set PSK with wrong mode
that: meraki_ssid:
- enable_ssid_number.data.enabled == True auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
auth_mode: open
psk: abc1234
delegate_to: localhost
register: psk_invalid
ignore_errors: yes
- name: Set PSK with wrong mode - debug:
meraki_ssid: msg: '{{ psk_invalid }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
auth_mode: open
psk: abc1234
delegate_to: localhost
register: psk_invalid
ignore_errors: yes
- debug: - assert:
msg: '{{ psk_invalid }}' that:
- psk_invalid.msg == 'PSK is only allowed when auth_mode is set to psk'
- assert: - name: Set PSK with invalid encryption mode
that: meraki_ssid:
- psk_invalid.msg == 'PSK is only allowed when auth_mode is set to psk' auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
auth_mode: psk
psk: abc1234
encryption_mode: eap
delegate_to: localhost
register: psk_invalid_mode
ignore_errors: yes
- name: Set PSK with invalid encryption mode - debug:
meraki_ssid: msg: '{{ psk_invalid_mode }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
auth_mode: psk
psk: abc1234
encryption_mode: eap
delegate_to: localhost
register: psk_invalid_mode
ignore_errors: yes
- debug: - assert:
msg: '{{ psk_invalid_mode }}' that:
- psk_invalid_mode.msg == 'PSK requires encryption_mode be set to wpa'
- assert: - name: Set PSK
that: meraki_ssid:
- psk_invalid_mode.msg == 'PSK requires encryption_mode be set to wpa' auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
auth_mode: psk
psk: abc1234567890
encryption_mode: wpa
delegate_to: localhost
register: psk
- name: Set PSK - debug:
meraki_ssid: msg: '{{ psk }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
auth_mode: psk
psk: abc1234567890
encryption_mode: wpa
delegate_to: localhost
register: psk
- debug: - assert:
msg: '{{ psk }}' that:
- psk.data.authMode == 'psk'
- psk.data.encryptionMode == 'wpa'
- psk.data.wpaEncryptionMode == 'WPA2 only'
- assert: - name: Enable click-through splash page
that: meraki_ssid:
- psk.data.authMode == 'psk' auth_key: '{{auth_key}}'
- psk.data.encryptionMode == 'wpa' state: present
- psk.data.wpaEncryptionMode == 'WPA2 only' org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
splash_page: Click-through splash page
delegate_to: localhost
register: splash_click
- name: Enable click-through splash page - debug:
meraki_ssid: msg: '{{ splash_click }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
splash_page: Click-through splash page
delegate_to: localhost
register: splash_click
- debug: - assert:
msg: '{{ splash_click }}' that:
- splash_click.data.splashPage == 'Click-through splash page'
- assert: - name: Configure RADIUS servers
that: meraki_ssid:
- splash_click.data.splashPage == 'Click-through splash page' auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
auth_mode: open-with-radius
radius_servers:
- host: 192.0.1.200
port: 1234
secret: abc98765
delegate_to: localhost
register: set_radius_server
- name: Configure RADIUS servers - debug:
meraki_ssid: msg: '{{ set_radius_server }}'
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
auth_mode: open-with-radius
radius_servers:
- host: 192.0.1.200
port: 1234
secret: abc98765
delegate_to: localhost
register: set_radius_server
- debug: - assert:
msg: '{{ set_radius_server }}' that:
- set_radius_server.data.radiusServers.0.host == '192.0.1.200'
always:
- name: Delete SSID
meraki_ssid:
auth_key: '{{auth_key}}'
state: absent
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
delegate_to: localhost
register: delete_ssid
- assert: - debug:
that: msg: '{{ delete_ssid }}'
- set_radius_server.data.radiusServers.0.host == '192.0.1.200'
- name: Delete SSID - assert:
meraki_ssid: that:
auth_key: '{{auth_key}}' - delete_ssid.data.name == 'Unconfigured SSID 2'
state: absent
org_name: '{{test_org_name}}'
net_name: TestNetSSID
name: AnsibleSSID
delegate_to: localhost
register: delete_ssid
- debug: - name: Delete test network
msg: '{{ delete_ssid }}' meraki_network:
auth_key: '{{auth_key}}'
state: absent
org_name: '{{test_org_name}}'
net_name: TestNetSSID
register: delete_net
- assert: - debug:
that: msg: '{{delete_net}}'
- delete_ssid.data.name == 'Unconfigured SSID 2'
- name: Delete test network
meraki_network:
auth_key: '{{auth_key}}'
state: absent
org_name: '{{test_org_name}}'
net_name: TestNetSSID
register: delete_net
- debug:
msg: '{{delete_net}}'