Meraki - Integration tests now clean up on failure (#42227)

* Added block and always support to meraki_network integration test

* Add blocks to admin and vlan integration test

* Resolved bad variable names
pull/42239/head
Kevin Breit 6 years ago committed by Dag Wieers
parent 75c8d8bfc2
commit f9cbdcd426

@ -1,254 +1,260 @@
# Test code for the Meraki Organization module # Test code for the Meraki Admin module
# Copyright: (c) 2018, Kevin Breit (@kbreit) # Copyright: (c) 2018, Kevin Breit (@kbreit)
# 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: Create new administrator - block:
meraki_admin: - name: Create new administrator
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: Jane Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+janedoe@{{email_domain}}' name: Jane Doe
orgAccess: read-only email: '{{email_prefix}}+janedoe@{{email_domain}}'
delegate_to: localhost orgAccess: read-only
register: create_orgaccess delegate_to: localhost
register: create_orgaccess
- name: Create new admin assertion
assert: - name: Create new admin assertion
that: assert:
- create_orgaccess.changed == true that:
- 'create_orgaccess.data.name == "Jane Doe"' - create_orgaccess.changed == true
- 'create_orgaccess.data.name == "Jane Doe"'
- name: Delete recently created administrator
meraki_admin: - name: Delete recently created administrator
auth_key: '{{auth_key}}' meraki_admin:
state: absent auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: absent
email: '{{email_prefix}}+janedoe@{{email_domain}}' org_name: '{{test_org_name}}'
delegate_to: localhost email: '{{email_prefix}}+janedoe@{{email_domain}}'
register: delete_one delegate_to: localhost
register: delete_one
- name: Create new administrator with org_id
meraki_admin: - name: Create new administrator with org_id
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_id: '{{test_org_id}}' state: present
name: Jane Doe org_id: '{{test_org_id}}'
email: '{{email_prefix}}+janedoe@{{email_domain}}' name: Jane Doe
orgAccess: read-only email: '{{email_prefix}}+janedoe@{{email_domain}}'
delegate_to: localhost orgAccess: read-only
register: create_orgaccess_id delegate_to: localhost
register: create_orgaccess_id
- name: Create new admin assertion
assert: - name: Create new admin assertion
that: assert:
- create_orgaccess_id.changed == true that:
- 'create_orgaccess_id.data.name == "Jane Doe"' - create_orgaccess_id.changed == true
- 'create_orgaccess_id.data.name == "Jane Doe"'
- name: Create administrator with tags
meraki_admin: - name: Create administrator with tags
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: John Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+johndoe@{{email_domain}}' name: John Doe
orgAccess: none email: '{{email_prefix}}+johndoe@{{email_domain}}'
tags: orgAccess: none
- { "tag": "production", "access": "read-only" } tags:
- { "tag": "beta", "access": "full" } - { "tag": "production", "access": "read-only" }
delegate_to: localhost - { "tag": "beta", "access": "full" }
register: create_tags delegate_to: localhost
register: create_tags
- assert:
that: - assert:
- create_tags.changed == true that:
- create_tags.data.name == "John Doe" - create_tags.changed == true
- create_tags.data.tags | length == 2 - create_tags.data.name == "John Doe"
- create_tags.data.tags | length == 2
- name: Create administrator with invalid tags
meraki_admin: - name: Create administrator with invalid tags
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: Jake Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+jakedoe@{{email_domain}}' name: Jake Doe
orgAccess: none email: '{{email_prefix}}+jakedoe@{{email_domain}}'
tags: orgAccess: none
- { "tag": "production", "access": "read-only" } tags:
- { "tag": "alpha", "access": "invalid" } - { "tag": "production", "access": "read-only" }
delegate_to: localhost - { "tag": "alpha", "access": "invalid" }
register: create_tags_invalid delegate_to: localhost
ignore_errors: yes register: create_tags_invalid
ignore_errors: yes
- assert:
that: - assert:
- '"400" in create_tags_invalid.msg' that:
# - '"must contain only valid tags" in create_tags_invalid.msg' - '"400" in create_tags_invalid.msg'
# - '"must contain only valid tags" in create_tags_invalid.msg'
- name: Create administrator with invalid tag permission
meraki_admin: - name: Create administrator with invalid tag permission
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: Jake Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+jakedoe@{{email_domain}}' name: Jake Doe
orgAccess: none email: '{{email_prefix}}+jakedoe@{{email_domain}}'
tags: orgAccess: none
- { "tag": "production", "access": "read-only" } tags:
- { "tag": "beta", "access": "invalid" } - { "tag": "production", "access": "read-only" }
delegate_to: localhost - { "tag": "beta", "access": "invalid" }
register: create_tags_invalid_permission delegate_to: localhost
ignore_errors: yes register: create_tags_invalid_permission
ignore_errors: yes
- assert:
that: - assert:
- '"400" in create_tags_invalid_permission.msg' that:
# - '"Invalid permission type" in create_tags_invalid_permission.msg' - '"400" in create_tags_invalid_permission.msg'
# - '"Invalid permission type" in create_tags_invalid_permission.msg'
- name: Make sure TestNet and TestNet2 are created
meraki_network: - name: Make sure TestNet and TestNet2 are created
auth_key: '{{auth_key}}' meraki_network:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
net_name: '{{item}}' org_name: '{{test_org_name}}'
type: switch net_name: '{{item}}'
loop: type: switch
- TestNet loop:
- TestNet2 - TestNet
- TestNet2
- name: Create administrator with networks
meraki_admin: - name: Create administrator with networks
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: Jim Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+jimdoe@{{email_domain}}' name: Jim Doe
orgAccess: none email: '{{email_prefix}}+jimdoe@{{email_domain}}'
networks: orgAccess: none
- { "network": "TestNet", "access": "read-only" } networks:
- { "network": "TestNet2", "access": "full" } - { "network": "TestNet", "access": "read-only" }
delegate_to: localhost - { "network": "TestNet2", "access": "full" }
register: create_network delegate_to: localhost
register: create_network
- assert:
that: - assert:
- create_network.changed == true that:
- create_network.data.name == "Jim Doe" - create_network.changed == true
- create_network.data.networks | length == 2 - create_network.data.name == "Jim Doe"
- create_network.data.networks | length == 2
- name: Update administrator
meraki_admin: - name: Update administrator
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: Jim Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+jimdoe@{{email_domain}}' name: Jim Doe
orgAccess: none email: '{{email_prefix}}+jimdoe@{{email_domain}}'
networks: orgAccess: none
- { "network": "TestNet", "access": "full" } networks:
delegate_to: localhost - { "network": "TestNet", "access": "full" }
register: update_network delegate_to: localhost
register: update_network
- assert:
that: - assert:
- update_network.changed == true that:
- update_network.data.networks.0.access == "full" - update_network.changed == true
- update_network.data.networks | length == 1 - update_network.data.networks.0.access == "full"
- update_network.data.networks | length == 1
- name: Update administrator for idempotency check
meraki_admin: - name: Update administrator for idempotency check
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: Jim Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+jimdoe@{{email_domain}}' name: Jim Doe
orgAccess: none email: '{{email_prefix}}+jimdoe@{{email_domain}}'
networks: orgAccess: none
- { "network": "TestNet", "access": "full" } networks:
delegate_to: localhost - { "network": "TestNet", "access": "full" }
register: update_network_idempotent delegate_to: localhost
register: update_network_idempotent
- assert:
that: - assert:
- update_network_idempotent.changed == false that:
- update_network_idempotent.changed == false
- name: Create administrator with invalid network
meraki_admin: - name: Create administrator with invalid network
auth_key: '{{auth_key}}' meraki_admin:
state: present auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: present
name: John Doe org_name: '{{test_org_name}}'
email: '{{email_prefix}}+John@{{email_domain}}' name: John Doe
orgAccess: none email: '{{email_prefix}}+John@{{email_domain}}'
networks: orgAccess: none
- { "network": "readnet", "access": "read-only" } networks:
delegate_to: localhost - { "network": "readnet", "access": "read-only" }
register: create_network_invalid delegate_to: localhost
ignore_errors: yes register: create_network_invalid
ignore_errors: yes
- assert:
that: - assert:
- '"No network found with the name" in create_network_invalid.msg' that:
# - '"400" in create_network_invalid.msg' - '"No network found with the name" in create_network_invalid.msg'
# - '"400" in create_network_invalid.msg'
- name: Query all administrators
meraki_admin: - name: Query all administrators
auth_key: '{{auth_key}}' meraki_admin:
state: query auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: query
delegate_to: localhost org_name: '{{test_org_name}}'
register: query_all delegate_to: localhost
register: query_all
- assert:
that: - assert:
- query_all.data | length == 4 that:
- query_all.changed == False - query_all.data | length == 4
- query_all.changed == False
- name: Query admin by name
meraki_admin: - name: Query admin by name
auth_key: '{{auth_key}}' meraki_admin:
state: query auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: query
name: Jane Doe org_name: '{{test_org_name}}'
delegate_to: localhost name: Jane Doe
register: query_name delegate_to: localhost
register: query_name
- name: Query admin by email
meraki_admin: - name: Query admin by email
auth_key: '{{auth_key}}' meraki_admin:
state: query auth_key: '{{auth_key}}'
org_name: '{{test_org_name}}' state: query
email: '{{email_prefix}}+janedoe@{{email_domain}}' org_name: '{{test_org_name}}'
delegate_to: localhost email: '{{email_prefix}}+janedoe@{{email_domain}}'
register: query_email delegate_to: localhost
register: query_email
- assert:
that: - assert:
- query_name.data.name == "Jane Doe" that:
- 'query_email.data.email == "{{email_prefix}}+janedoe@{{email_domain}}"' - query_name.data.name == "Jane Doe"
- 'query_email.data.email == "{{email_prefix}}+janedoe@{{email_domain}}"'
- name: Delete administrators
meraki_admin: always:
auth_key: '{{auth_key}}' #############################################################################
state: absent # Tear down starts here
org_name: '{{test_org_name}}' #############################################################################
email: '{{item}}' - name: Delete administrators
delegate_to: localhost meraki_admin:
register: delete_all auth_key: '{{auth_key}}'
loop: state: absent
- '{{email_prefix}}+janedoe@{{email_domain}}' org_name: '{{test_org_name}}'
- '{{email_prefix}}+johndoe@{{email_domain}}' email: '{{item}}'
- '{{email_prefix}}+jimdoe@{{email_domain}}' delegate_to: localhost
register: delete_all
- name: Query all administrators ignore_errors: yes
meraki_admin: loop:
auth_key: '{{auth_key}}' - '{{email_prefix}}+janedoe@{{email_domain}}'
state: query - '{{email_prefix}}+johndoe@{{email_domain}}'
org_name: '{{test_org_name}}' - '{{email_prefix}}+jimdoe@{{email_domain}}'
delegate_to: localhost
register: query_all_deleted - name: Query all administrators
meraki_admin:
- assert: auth_key: '{{auth_key}}'
that: state: query
- query_all_deleted.data | length == 1 org_name: '{{test_org_name}}'
delegate_to: localhost
register: query_all_deleted
- assert:
that:
- query_all_deleted.data | length == 1

@ -3,245 +3,234 @@
# 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: Create network without type - block:
meraki_network: - name: Create network without type
auth_key: '{{ auth_key }}' meraki_network:
state: present auth_key: '{{ auth_key }}'
org_name: '{{test_org_name}}' state: present
net_name: IntTestNetwork org_name: '{{test_org_name}}'
timezone: America/Chicago net_name: IntTestNetwork
delegate_to: localhost timezone: America/Chicago
register: create_net_no_type delegate_to: localhost
ignore_errors: yes register: create_net_no_type
ignore_errors: yes
- name: Create network without organization
meraki_network: - name: Create network without organization
auth_key: '{{ auth_key }}' meraki_network:
state: present auth_key: '{{ auth_key }}'
net_name: IntTestNetwork state: present
timezone: America/Chicago net_name: IntTestNetwork
delegate_to: localhost timezone: America/Chicago
register: create_net_no_org delegate_to: localhost
ignore_errors: yes register: create_net_no_org
ignore_errors: yes
- name: Create network with type switch
meraki_network: - name: Create network with type switch
auth_key: '{{ auth_key }}' meraki_network:
state: present auth_key: '{{ auth_key }}'
org_name: '{{test_org_name}}' state: present
net_name: IntTestNetworkSwitch org_name: '{{test_org_name}}'
type: switch net_name: IntTestNetworkSwitch
timezone: America/Chicago type: switch
delegate_to: localhost timezone: America/Chicago
register: create_net_switch delegate_to: localhost
register: create_net_switch
- name: Create network with type switch by org ID
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_id: '{{test_org_id}}'
net_name: IntTestNetworkSwitchOrgID
type: switch
timezone: America/Chicago
delegate_to: localhost
register: create_net_switch_org_id
- name: Create network with type appliance and no timezone
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkAppliance
type: appliance
delegate_to: localhost
register: create_net_appliance_no_tz
- name: Create network with type wireless
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkWireless
type: wireless
timezone: America/Chicago
delegate_to: localhost
register: create_net_wireless
- name: Create network with type wireless and check for idempotency
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkWireless
type: wireless
timezone: America/Chicago
delegate_to: localhost
register: create_net_wireless_idempotent
- name: Create network with type combined
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkCombined
type: combined
timezone: America/Chicago
delegate_to: localhost
register: create_net_combined
- name: Create network with one tag
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTag
type: switch
timezone: America/Chicago
tags: first_tag
delegate_to: localhost
register: create_net_tag
- debug:
msg: '{{create_net_tag}}'
- name: Create network with two tags
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag
delegate_to: localhost
register: create_net_tags
- debug:
msg: '{{create_net_tags}}'
- name: Modify network
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag, third_tag
delegate_to: localhost
register: create_net_modified
- name: Modify network with idempotency
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag, third_tag
delegate_to: localhost
register: create_net_modified_idempotent
- name: Present assertions
assert:
that:
- create_net_no_type.status == 500
- '"org_name or org_id parameters are required" in create_net_no_org.msg'
- '"IntTestNetworkAppliance" in create_net_appliance_no_tz.data.name'
- create_net_appliance_no_tz.changed == True
- '"IntTestNetworkSwitch" in create_net_switch.data.name'
- '"IntTestNetworkSwitchOrgID" in create_net_switch_org_id.data.name'
- '"IntTestNetworkWireless" in create_net_wireless.data.name'
- create_net_wireless_idempotent.changed == False
- '"first_tag" in create_net_tag.data.tags'
- '"second_tag" in create_net_tags.data.tags'
- '"third_tag" in create_net_modified.data.tags'
- create_net_modified.changed == True
- create_net_modified_idempotent.changed == False
- name: Query all networks
meraki_network:
auth_key: '{{ auth_key }}'
state: query
org_name: '{{test_org_name}}'
delegate_to: localhost
register: net_query_all
- name: Query one network - name: Create network with type switch by org ID
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: query state: present
org_name: '{{test_org_name}}' org_id: '{{test_org_id}}'
net_name: IntTestNetworkSwitch net_name: IntTestNetworkSwitchOrgID
delegate_to: localhost type: switch
register: net_query_one timezone: America/Chicago
delegate_to: localhost
- name: Query assertions register: create_net_switch_org_id
assert:
that: - name: Create network with type appliance and no timezone
# - net_query_all.data | length == 7 meraki_network:
- 'net_query_one.data.name == "IntTestNetworkSwitch"' auth_key: '{{ auth_key }}'
state: present
- name: Delete network without org org_name: '{{test_org_name}}'
meraki_network: net_name: IntTestNetworkAppliance
auth_key: '{{ auth_key }}' type: appliance
state: absent delegate_to: localhost
net_name: IntTestNetworkSwitch register: create_net_appliance_no_tz
delegate_to: localhost
register: delete_all_no_org
ignore_errors: yes
- debug:
msg: '{{delete_all_no_org}}'
- name: Delete network by org ID - name: Create network with type wireless
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: absent state: present
org_id: '{{test_org_id}}' org_name: '{{test_org_name}}'
net_name: IntTestNetworkSwitchOrgID net_name: IntTestNetworkWireless
delegate_to: localhost type: wireless
register: delete_net_org_id timezone: America/Chicago
delegate_to: localhost
- debug: register: create_net_wireless
msg: '{{delete_net_org_id}}'
- name: Create network with type wireless and check for idempotency
- name: Query after delete with org ID meraki_network:
meraki_network: auth_key: '{{ auth_key }}'
auth_key: '{{ auth_key }}' state: present
state: query org_name: '{{test_org_name}}'
org_name: '{{test_org_name}}' net_name: IntTestNetworkWireless
delegate_to: localhost type: wireless
register: query_deleted_org_id timezone: America/Chicago
delegate_to: localhost
- name: Delete all networks register: create_net_wireless_idempotent
meraki_network:
auth_key: '{{ auth_key }}' - name: Create network with type combined
state: absent meraki_network:
org_name: '{{test_org_name}}' auth_key: '{{ auth_key }}'
net_name: '{{ item }}' state: present
delegate_to: localhost org_name: '{{test_org_name}}'
register: delete_all net_name: IntTestNetworkCombined
loop: type: combined
- IntTestNetworkSwitch timezone: America/Chicago
- IntTestNetworkWireless delegate_to: localhost
- IntTestNetworkAppliance register: create_net_combined
- IntTestNetworkCombined
- IntTestNetworkTag
- IntTestNetworkTags
- name: Query after delete all - name: Create network with one tag
meraki_network: meraki_network:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
state: query state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
delegate_to: localhost net_name: IntTestNetworkTag
register: query_deleted type: switch
timezone: America/Chicago
tags: first_tag
delegate_to: localhost
register: create_net_tag
- debug:
msg: '{{create_net_tag}}'
- name: Delete assertions - name: Create network with two tags
assert: meraki_network:
that: auth_key: '{{ auth_key }}'
- '"org_name or org_id parameters are required" in delete_all_no_org.msg' state: present
# - query_deleted_org_id.data | length == 6 org_name: '{{test_org_name}}'
# - query_deleted.data | length == 0 net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag
delegate_to: localhost
register: create_net_tags
- debug:
msg: '{{create_net_tags}}'
- name: Modify network
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag, third_tag
delegate_to: localhost
register: create_net_modified
- name: Modify network with idempotency
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetworkTags
type: switch
timezone: America/Chicago
tags: first_tag, second_tag, third_tag
delegate_to: localhost
register: create_net_modified_idempotent
- name: Present assertions
assert:
that:
- create_net_no_type.status == 500
- '"org_name or org_id parameters are required" in create_net_no_org.msg'
- '"IntTestNetworkAppliance" in create_net_appliance_no_tz.data.name'
- create_net_appliance_no_tz.changed == True
- '"IntTestNetworkSwitch" in create_net_switch.data.name'
- '"IntTestNetworkSwitchOrgID" in create_net_switch_org_id.data.name'
- '"IntTestNetworkWireless" in create_net_wireless.data.name'
- create_net_wireless_idempotent.changed == False
- '"first_tag" in create_net_tag.data.tags'
- '"second_tag" in create_net_tags.data.tags'
- '"third_tag" in create_net_modified.data.tags'
- create_net_modified.changed == True
- create_net_modified_idempotent.changed == False
- name: Query all networks
meraki_network:
auth_key: '{{ auth_key }}'
state: query
org_name: '{{test_org_name}}'
delegate_to: localhost
register: net_query_all
- name: Query one network
meraki_network:
auth_key: '{{ auth_key }}'
state: query
org_name: '{{test_org_name}}'
net_name: IntTestNetworkSwitch
delegate_to: localhost
register: net_query_one
- name: Query assertions
assert:
that:
- 'net_query_one.data.name == "IntTestNetworkSwitch"'
#############################################################################
# Tear down starts here
#############################################################################
always:
- name: Delete network without org
meraki_network:
auth_key: '{{ auth_key }}'
state: absent
net_name: IntTestNetworkSwitch
delegate_to: localhost
register: delete_all_no_org
ignore_errors: yes
- name: Delete network by org ID
meraki_network:
auth_key: '{{ auth_key }}'
state: absent
org_id: '{{test_org_id}}'
net_name: IntTestNetworkSwitchOrgID
delegate_to: localhost
register: delete_net_org_id
- name: Query after delete with org ID
meraki_network:
auth_key: '{{ auth_key }}'
state: query
org_name: '{{test_org_name}}'
delegate_to: localhost
register: query_deleted_org_id
- name: Delete all networks
meraki_network:
auth_key: '{{ auth_key }}'
state: absent
org_name: '{{test_org_name}}'
net_name: '{{ item }}'
delegate_to: localhost
register: delete_all
ignore_errors: yes
loop:
- IntTestNetworkSwitch
- IntTestNetworkWireless
- IntTestNetworkAppliance
- IntTestNetworkCombined
- IntTestNetworkTag
- IntTestNetworkTags
- assert:
that:
- 'delete_all_no_org.msg == "org_name or org_id parameters are required"'

@ -1,303 +1,307 @@
# Test code for the Meraki Organization module # Test code for the Meraki VLAN module
# Copyright: (c) 2018, Kevin Breit (@kbreit) # Copyright: (c) 2018, Kevin Breit (@kbreit)
# 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_vlan: - name: Use an invalid domain
auth_key: '{{ auth_key }}' meraki_vlan:
host: marrrraki.com auth_key: '{{ auth_key }}'
state: present host: marrrraki.com
org_name: '{{test_org_name}}' 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_vlan: - name: Disable HTTP
auth_key: '{{ auth_key }}' meraki_vlan:
use_https: false auth_key: '{{ auth_key }}'
state: query use_https: false
org_name: '{{test_org_name}}' state: query
output_level: debug output_level: debug
delegate_to: localhost delegate_to: localhost
register: http register: http
ignore_errors: yes 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: '{{test_net_name}}' net_name: '{{test_net_name}}'
type: appliance type: appliance
delegate_to: localhost delegate_to: localhost
- name: Create VLAN - name: Create VLAN
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.1 appliance_ip: 192.168.250.1
delegate_to: localhost delegate_to: localhost
register: create_vlan register: create_vlan
- debug: - debug:
msg: '{{create_vlan}}' msg: '{{create_vlan}}'
- assert: - assert:
that: that:
- create_vlan.data.id == 2 - create_vlan.data.id == 2
- create_vlan.changed == True - create_vlan.changed == True
- name: Update VLAN - name: Update VLAN
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan register: update_vlan
- debug: - debug:
msg: '{{update_vlan}}' msg: '{{update_vlan}}'
- assert: - assert:
that: that:
- update_vlan.data.applianceIp == '192.168.250.2' - update_vlan.data.applianceIp == '192.168.250.2'
- update_vlan.changed == True - update_vlan.changed == True
- name: Update VLAN with idempotency - name: Update VLAN with idempotency
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan_idempotent register: update_vlan_idempotent
- debug: - debug:
msg: '{{update_vlan_idempotent}}' msg: '{{update_vlan_idempotent}}'
- assert: - assert:
that: that:
- update_vlan_idempotent.changed == False - update_vlan_idempotent.changed == False
- name: Add IP assignments and reserved IP ranges - name: Add IP assignments and reserved IP ranges
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
- mac: "12:34:56:78:90:12" - mac: "12:34:56:78:90:12"
ip: 192.168.250.11 ip: 192.168.250.11
name: another_fixed_ip name: another_fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
- start: 192.168.250.100 - start: 192.168.250.100
end: 192.168.250.120 end: 192.168.250.120
comment: reserved_range_high comment: reserved_range_high
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan_add_ip register: update_vlan_add_ip
- debug: - debug:
msg: '{{update_vlan_add_ip}}' msg: '{{update_vlan_add_ip}}'
- assert: - assert:
that: that:
- update_vlan_add_ip.changed == True - update_vlan_add_ip.changed == True
- update_vlan_add_ip.data.fixedIpAssignments | length == 2 - update_vlan_add_ip.data.fixedIpAssignments | length == 2
- update_vlan_add_ip.data.reservedIpRanges | length == 2 - update_vlan_add_ip.data.reservedIpRange | length == 2
- name: Remove IP assignments and reserved IP ranges - name: Remove IP assignments and reserved IP ranges
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan_remove_ip register: update_vlan_remove_ip
- debug: - debug:
msg: '{{update_vlan_remove_ip}}' msg: '{{update_vlan_remove_ip}}'
- assert: - assert:
that: that:
- update_vlan_remove_ip.changed == True - update_vlan_remove_ip.changed == True
- update_vlan_remove_ip.data.fixedIpAssignments | length == 1 - update_vlan_remove_ip.data.fixedIpAssignments | length == 1
- update_vlan_remove_ip.data.reservedIpRanges | length == 1 - update_vlan_remove_ip.data.reservedIpRange | length == 1
- name: Update VLAN with idempotency - name: Update VLAN with idempotency
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: opendns dns_nameservers: opendns
delegate_to: localhost delegate_to: localhost
register: update_vlan_idempotent register: update_vlan_idempotent
- debug: - debug:
msg: '{{update_vlan_idempotent}}' msg: '{{update_vlan_idempotent}}'
- assert: - assert:
that: that:
- update_vlan_idempotent.changed == False - update_vlan_idempotent.changed == False
- name: Update VLAN with list of DNS entries - name: Update VLAN with list of DNS entries
meraki_vlan: meraki_vlan:
auth_key: '{{auth_key}}' auth_key: '{{auth_key}}'
state: present state: present
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
name: TestVLAN name: TestVLAN
subnet: 192.168.250.0/24 subnet: 192.168.250.0/24
appliance_ip: 192.168.250.2 appliance_ip: 192.168.250.2
fixed_ip_assignments: fixed_ip_assignments:
- mac: "13:37:de:ad:be:ef" - mac: "13:37:de:ad:be:ef"
ip: 192.168.250.10 ip: 192.168.250.10
name: fixed_ip name: fixed_ip
reserved_ip_range: reserved_ip_range:
- start: 192.168.250.10 - start: 192.168.250.10
end: 192.168.250.20 end: 192.168.250.20
comment: reserved_range comment: reserved_range
dns_nameservers: 1.1.1.1;8.8.8.8 dns_nameservers: 1.1.1.1;8.8.8.8
delegate_to: localhost delegate_to: localhost
register: update_vlan_dns_list register: update_vlan_dns_list
- debug: - debug:
msg: '{{update_vlan_dns_list}}' msg: '{{update_vlan_dns_list}}'
- assert: - assert:
that: that:
- '"1.1.1.1" in update_vlan_dns_list.data.dnsNameservers' - '"1.1.1.1" in update_vlan_dns_list.data.dnsNameservers'
- update_vlan_dns_list.changed == True - update_vlan_dns_list.changed == True
- name: Query all VLANs in network - name: Query all VLANs in network
meraki_vlan: meraki_vlan:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
state: query state: query
delegate_to: localhost delegate_to: localhost
register: query_vlans register: query_vlans
- debug: - debug:
msg: '{{query_vlans}}' msg: '{{query_vlans}}'
- assert: - assert:
that: that:
- query_vlans.data | length >= 2 - query_vlans.data | length >= 2
- query_vlans.data.1.id == 2 - query_vlans.data.1.id == 2
- query_vlans.changed == False - query_vlans.changed == False
- name: Query single VLAN - name: Query single VLAN
meraki_vlan: meraki_vlan:
auth_key: '{{ auth_key }}' auth_key: '{{ auth_key }}'
org_name: '{{test_org_name}}' org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}' net_name: '{{test_net_name}}'
vlan_id: 2 vlan_id: 2
state: query state: query
output_level: debug output_level: debug
delegate_to: localhost delegate_to: localhost
register: query_vlan register: query_vlan
- debug: - debug:
msg: '{{query_vlan}}' msg: '{{query_vlan}}'
- assert: - assert:
that: that:
- query_vlan.data.id == 2 - query_vlan.data.id == 2
- query_vlan.changed == False - query_vlan.changed == False
- name: Delete VLAN always:
meraki_vlan: #############################################################################
auth_key: '{{auth_key}}' # Tear down starts here
state: absent #############################################################################
org_name: '{{test_org_name}}' - name: Delete VLAN
net_name: '{{test_net_name}}' meraki_vlan:
vlan_id: 2 auth_key: '{{auth_key}}'
delegate_to: localhost state: absent
register: delete_vlan org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}'
- debug: vlan_id: 2
msg: '{{delete_vlan}}' delegate_to: localhost
register: delete_vlan
- debug:
msg: '{{delete_vlan}}'

Loading…
Cancel
Save