summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/meraki_admin/tasks/main.yml
blob: 0e8ff2791f092192c562ad49248e01392c6453f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# Test code for the Meraki Admin module
# Copyright: (c) 2018, Kevin Breit (@kbreit)

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- block:
  - name: Create new administrator
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      name: Jane Doe
      email: '{{email_prefix}}+janedoe@{{email_domain}}'
      orgAccess: read-only
    delegate_to: localhost
    register: create_orgaccess

  - name: Create new admin assertion
    assert:
      that:
        - create_orgaccess.changed == true
        - 'create_orgaccess.data.name == "Jane Doe"'

  - name: Delete recently created administrator
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: absent
      org_name: '{{test_org_name}}'
      email: '{{email_prefix}}+janedoe@{{email_domain}}'
    delegate_to: localhost
    register: delete_one

  - name: Create new administrator with org_id
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: present
      org_id: '{{test_org_id}}'
      name: Jane Doe
      email: '{{email_prefix}}+janedoe@{{email_domain}}'
      orgAccess: read-only
    delegate_to: localhost
    register: create_orgaccess_id

  - name: Create new admin assertion
    assert:
      that:
        - create_orgaccess_id.changed == true
        - 'create_orgaccess_id.data.name == "Jane Doe"'

  - name: Create administrator with tags
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      name: John Doe
      email: '{{email_prefix}}+johndoe@{{email_domain}}'
      orgAccess: none
      tags:
        - { "tag": "production", "access": "read-only" }
        - { "tag": "beta", "access": "full" }
    delegate_to: localhost
    register: create_tags

  - assert:
      that:
        - create_tags.changed == true
        - create_tags.data.name == "John Doe"
        - create_tags.data.tags | length == 2

  - name: Create administrator with invalid tags
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      name: Jake Doe
      email: '{{email_prefix}}+jakedoe@{{email_domain}}'
      orgAccess: none
      tags:
        - { "tag": "production", "access": "read-only" }
        - { "tag": "alpha", "access": "invalid" }
    delegate_to: localhost
    register: create_tags_invalid
    ignore_errors: yes

  - assert:
      that:
        - '"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:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      name: Jake Doe
      email: '{{email_prefix}}+jakedoe@{{email_domain}}'
      orgAccess: none
      tags:
        - { "tag": "production", "access": "read-only" }
        - { "tag": "beta", "access": "invalid" }
    delegate_to: localhost
    register: create_tags_invalid_permission
    ignore_errors: yes

  - assert:
      that:
        - '"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:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      net_name: '{{item}}'
      type: switch
    loop:
      - TestNet
      - TestNet2

  - name: Create administrator with networks
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      name: Jim Doe
      email: '{{email_prefix}}+jimdoe@{{email_domain}}'
      orgAccess: none
      networks:
        - { "network": "TestNet", "access": "read-only" }
        - { "network": "TestNet2", "access": "full" }
    delegate_to: localhost
    register: create_network

  - assert:
      that:
        - create_network.changed == true
        - create_network.data.name == "Jim Doe"
        - create_network.data.networks | length == 2

  - name: Update administrator
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      name: Jim Doe
      email: '{{email_prefix}}+jimdoe@{{email_domain}}'
      orgAccess: none
      networks:
        - { "network": "TestNet", "access": "full" }
    delegate_to: localhost
    register: update_network

  - assert:
      that:
        - update_network.changed == true
        - update_network.data.networks.0.access == "full"
        - update_network.data.networks | length == 1

  - name: Update administrator for idempotency check
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      name: Jim Doe
      email: '{{email_prefix}}+jimdoe@{{email_domain}}'
      orgAccess: none
      networks:
        - { "network": "TestNet", "access": "full" }
    delegate_to: localhost
    register: update_network_idempotent

  - assert:
      that:
        - update_network_idempotent.changed == false

  - name: Create administrator with invalid network
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: present
      org_name: '{{test_org_name}}'
      name: John Doe
      email: '{{email_prefix}}+John@{{email_domain}}'
      orgAccess: none
      networks:
        - { "network": "readnet", "access": "read-only" }
    delegate_to: localhost
    register: create_network_invalid
    ignore_errors: yes

  - assert:
      that:
        - '"No network found with the name" in create_network_invalid.msg'
        # - '"400" in create_network_invalid.msg'

  - name: Query all administrators
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: query
      org_name: '{{test_org_name}}'
    delegate_to: localhost
    register: query_all

  - assert:
      that:
        - query_all.data | length == 4
        - query_all.changed == False

  - name: Query admin by name
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: query
      org_name: '{{test_org_name}}'
      name: Jane Doe
    delegate_to: localhost
    register: query_name

  - name: Query admin by email
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: query
      org_name: '{{test_org_name}}'
      email: '{{email_prefix}}+janedoe@{{email_domain}}'
    delegate_to: localhost
    register: query_email

  - assert:
      that:
        - query_name.data.name == "Jane Doe"
        - 'query_email.data.email == "{{email_prefix}}+janedoe@{{email_domain}}"'

  always:
  #############################################################################
  # Tear down starts here
  #############################################################################
  - name: Delete administrators
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: absent
      org_name: '{{test_org_name}}'
      email: '{{item}}'
    delegate_to: localhost
    register: delete_all
    ignore_errors: yes
    loop:
        - '{{email_prefix}}+janedoe@{{email_domain}}'
        - '{{email_prefix}}+johndoe@{{email_domain}}'
        - '{{email_prefix}}+jimdoe@{{email_domain}}'

  - name: Query all administrators
    meraki_admin:
      auth_key: '{{auth_key}}'
      state: query
      org_name: '{{test_org_name}}'
    delegate_to: localhost
    register: query_all_deleted

  - assert:
      that:
        - query_all_deleted.data | length == 1