-
Notifications
You must be signed in to change notification settings - Fork 2
/
meraki.show.yaml
197 lines (176 loc) · 6.59 KB
/
meraki.show.yaml
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
---
#------------------------------------------------------------------------------
# Shows Cisco Meraki Org, Admin, Networks, and Devices Information
#
# Requires the following environment variables:
# export MERAKI_DASHBOARD_API_KEY='EXAMPLE+KEYc320e12ee407159487a4cabc41abb'
#
# Run with
# ansible-playbook meraki.show.yaml
# ansible-playbook -v meraki.show.yaml # use -v to see the intermediate results
#------------------------------------------------------------------------------
- name: Show Meraki Admins, Organizations, Networks, and Devices
hosts: localhost
vars_files:
- vars/main.yaml
gather_facts: no
pre_tasks:
- name: Check Required Environment Variables
delegate_to: localhost
vars:
env_vars:
- MERAKI_DASHBOARD_API_KEY
loop: "{{ env_vars }}"
ansible.builtin.assert:
that:
- lookup('env', item) # is defined does not work
fail_msg: |
X Please set the required environment variable {{ item }} in your terminal:
export {{ item }}=__________
success_msg: |
✔ Environment variable {{ item }} is set
tasks:
- name: Get Organizations for user's authentication key
delegate_to: localhost
cisco.meraki.organizations_info:
# organizationId: "{{ meraki_org_id }}"
register: results
- name: Show Meraki Orgs
delegate_to: localhost
vars:
hide: ["url"]
# maxw: 40
rows: "{{ results.meraki_response }}"
temp: "{{ lookup('template', 'templates/list_of_dicts.j2') }}"
ansible.builtin.debug:
msg: "{{ temp }}"
- name: Set org_names and org_ids
ansible.builtin.set_fact:
org_names: "{{ results.meraki_response | community.general.json_query('[*].name') }}"
org_ids: "{{ results.meraki_response | community.general.json_query('[*].id') }}"
- name: Get Org Administrators
delegate_to: localhost
loop: "{{ org_ids }}"
cisco.meraki.organizations_admins_info:
organizationId: "{{ item }}"
register: results
- name: Show Meraki Org Admins
delegate_to: localhost
vars:
hide: ["authenticationMethod"]
maxw: 30
rows: "{{ results.results | community.general.json_query('[*].meraki_response') | first }}"
temp: "{{ lookup('template', 'templates/list_of_dicts.j2') }}"
ansible.builtin.debug:
msg: "{{ temp }}"
- name: Get All Networks
delegate_to: localhost
loop: "{{ org_ids }}"
cisco.meraki.networks_info:
organizationId: "{{ item }}"
register: results
- name: Set networks
ansible.builtin.set_fact:
networks: "{{ results.results[0].meraki_response }}"
- name: Show All Networks
delegate_to: localhost
vars:
hide: ["enrollmentString", "url"]
maxw: 30
rows: "{{ networks }}"
# rows: "{{ results.results | community.general.json_query('[*].meraki_response') | first }}"
temp: "{{ lookup('template', 'templates/list_of_dicts.j2') }}"
ansible.builtin.debug:
msg: "{{ temp }}"
- name: Get All Devices in the Organization
delegate_to: localhost
loop: "{{ org_ids }}"
cisco.meraki.devices_info:
organizationId: "{{ item }}"
register: results
- name: Show All Meraki Devices
delegate_to: localhost
vars:
hide: ["address", "firmware", "lat", "lng", "notes", "url"]
maxw: 30
# rows: "{{ results.meraki_response }}"
rows: "{{ results.results | community.general.json_query('[*].meraki_response') | first }}"
temp: "{{ lookup('template', 'templates/list_of_dicts.j2') }}"
ansible.builtin.debug:
msg: "{{ temp }}"
- name: Get All Wireless SSIDs
loop: "{{ networks | selectattr('productTypes', 'contains', 'wireless') }}"
cisco.meraki.networks_wireless_ssids_info:
networkId: "{{ item.id }}"
register: ssid_results
- name: Set networks_wireless_ssids
ansible.builtin.set_fact:
networks_wireless_ssids: "{{ ssid_results.results | community.general.json_query('[*].meraki_response') | first }}"
- name: Show Wireless SSIDs' General Configuration
delegate_to: localhost
vars:
# hide: ["address", "firmware", "lat", "lng", "notes", "url"]
head:
- enabled
- number
- name
- visible
- authMode
- authModeencryptionMode
- wpaEncryptionMode
- availableOnAllAps
- splashPage
- namedVlans
- ipAssignmentMode
maxw: 30
# rows: "{{ results.meraki_response }}"
# rows: "{{ ssid_results.results | community.general.json_query('[*].meraki_response') | first }}"
rows: "{{ networks_wireless_ssids }}"
temp: "{{ lookup('template', 'templates/list_of_dicts.j2') }}"
ansible.builtin.debug:
msg: "{{ temp }}"
- name: Wireless SSIDs' RADIUS Configuration
delegate_to: localhost
vars:
# hide: ["address", "firmware", "lat", "lng", "notes", "url"]
head:
# - enabled
# - number
- name
# - radiusAuthenticationNasId
# - radiusCalledStationId
- radiusServers
# - radiusAccountingServers
- radiusServerTimeout
- radiusServerAttemptsLimit
- radiusTestingEnabled
# - radiusAccountingEnabled
- radiusAccountingInterimInterval
- radiusAttributeForGroupPolicies
- radiusCoaEnabled
# - radiusFallbackEnabled
# - radiusProxyEnabled
maxw: 30
# rows: "{{ results.meraki_response }}"
rows: "{{ ssid_results.results | community.general.json_query('[*].meraki_response') | first }}"
temp: "{{ lookup('template', 'templates/list_of_dicts.j2') }}"
ansible.builtin.debug:
msg: "{{ temp }}"
- name: Create directory | {{ dir_configs | default("configs") }}
delegate_to: localhost
ansible.builtin.file:
path: "{{ dir_configs | default('configs') }}"
state: directory
mode: "0700"
- name: To YAML File | {{ dir_configs | default("configs") }}/networks_wireless_ssids.yaml
delegate_to: localhost
when:
- networks_wireless_ssids is defined
- networks_wireless_ssids | count > 0
vars:
resource_name: networks_wireless_ssids
resources: "{{ networks_wireless_ssids }}"
ansible.builtin.template:
src: templates/resource_template.j2
dest: "{{ dir_configs | default('configs') }}/networks_wireless_ssids.yaml"
mode: "0644"