1# Test code for the Meraki Organization module
2# Copyright: (c) 2018, Kevin Breit (@kbreit)
3
4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5---
6- block:
7  - name: Test an API key is provided
8    fail:
9      msg: Please define an API key
10    when: auth_key is not defined
11
12  - name: Use an invalid domain
13    meraki_config_template:
14      auth_key: '{{ auth_key }}'
15      host: marrrraki.com
16      state: query
17      org_name: DevTestOrg
18      output_level: debug
19    delegate_to: localhost
20    register: invalid_domain
21    ignore_errors: yes
22
23  - name: Connection assertions
24    assert:
25      that:
26        - '"Failed to connect to" in invalid_domain.msg'
27
28  - name: Query all configuration templates
29    meraki_config_template:
30      auth_key: '{{auth_key}}'
31      state: query
32      org_name: DevTestOrg
33    register: get_all
34
35  - name: Delete non-existant configuration template
36    meraki_config_template:
37      auth_key: '{{auth_key}}'
38      state: absent
39      org_name: DevTestOrg
40      config_template: DevConfigTemplateInvalid
41    register: deleted
42    ignore_errors: yes
43
44  - assert:
45      that:
46        - '"No configuration template named" in deleted.msg'
47
48  - name: Create a network
49    meraki_network:
50      auth_key: '{{auth_key}}'
51      state: present
52      org_name: '{{ test_org_name }}'
53      net_name: '{{ test_net_name }}'
54      type: appliance
55    delegate_to: localhost
56
57  - name: Bind a template to a network
58    meraki_config_template:
59      auth_key: '{{auth_key}}'
60      state: present
61      org_name: '{{ test_org_name }}'
62      net_name: '{{ test_net_name }}'
63      config_template: DevConfigTemplate
64    register: bind
65
66  - assert:
67      that:
68        bind.changed == True
69
70  - name: Bind a template to a network when it's already bound
71    meraki_config_template:
72      auth_key: '{{auth_key}}'
73      state: present
74      org_name: '{{ test_org_name }}'
75      net_name: '{{ test_net_name }}'
76      config_template: DevConfigTemplate
77    register: bind_invalid
78    ignore_errors: yes
79
80  - assert:
81      that:
82        - bind_invalid.changed == False
83
84  - name: Unbind a template from a network
85    meraki_config_template:
86      auth_key: '{{auth_key}}'
87      state: absent
88      org_name: '{{ test_org_name }}'
89      net_name: '{{ test_net_name }}'
90      config_template: DevConfigTemplate
91    register: unbind
92
93  - assert:
94      that:
95        unbind.changed == True
96
97  - name: Unbind a template from a network when it's not bound
98    meraki_config_template:
99      auth_key: '{{auth_key}}'
100      state: absent
101      org_name: '{{ test_org_name }}'
102      net_name: '{{ test_net_name }}'
103      config_template: DevConfigTemplate
104    register: unbind_invalid
105
106  - assert:
107      that:
108        unbind_invalid.changed == False
109
110  always:
111  - name: Delete network
112    meraki_network:
113      auth_key: '{{auth_key}}'
114      state: absent
115      org_name: '{{ test_org_name }}'
116      net_name: '{{ test_net_name }}'
117    delegate_to: localhost