-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_mqtt.yml
73 lines (70 loc) · 2.36 KB
/
remove_mqtt.yml
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
---
- name: Query for existing MQTT brokers
block:
- name: Query for existing MQTT brokers on Network {{ meraki_mt_configuration.network.name }}
ansible.builtin.uri:
url: "{{ dashboard_base_url }}/networks/{{ network_id }}/mqttBrokers"
method: GET
status_code: 200
headers:
Content-Type: application/json
Accept: application/json
X-Cisco-Meraki-API-Key: "{{ auth_key }}"
until: broker_result.status != 429
delay: 5
retries: 3
register: broker_result
when: meraki_mt_configuration is defined
rescue:
- name: Something went wrong...
ansible.builtin.debug:
msg: "ERROR: {{ broker_result }}"
- name: Add discovered brokers to dict
ansible.builtin.set_fact:
mqtt_broker_ids: >-
{{ mqtt_broker_ids | default({}) | combine(
{
result.name: {
"id": result.id,
}
}
) }}
loop: "{{ broker_result.json }}"
loop_control:
loop_var: result
when: broker_result.status == 200
- name: Delete MQTT Broker
block:
- name: Disable MQTT Broker before deletion
cisco.meraki.networks_sensor_mqtt_brokers:
meraki_api_key: "{{ auth_key }}"
networkId: "{{ network_id }}"
state: present
enabled: false
mqttBrokerId: "{{ mqtt_broker_ids[broker.name].id }}"
loop: "{{ meraki_mt_configuration.mqtt_brokers | list }}"
loop_control:
loop_var: broker
when: mqtt_broker_ids[broker.name] is defined
- name: Deleting MQTT Broker for Network {{ meraki_mt_configuration.network.name }}
ansible.builtin.uri:
url: "{{ dashboard_base_url }}/networks/{{ network_id }}/mqttBrokers/{{ mqtt_broker_ids[broker.name].id }}"
method: DELETE
status_code: 204
headers:
Content-Type: application/json
Accept: application/json
X-Cisco-Meraki-API-Key: "{{ auth_key }}"
changed_when: delete_broker_result.status == 204
until: delete_broker_result.status != 429
delay: 5
retries: 3
register: delete_broker_result
when: mqtt_broker_ids[broker.name] is defined
loop: "{{ meraki_mt_configuration.mqtt_brokers }}"
loop_control:
loop_var: broker
rescue:
- name: Something went wrong...
ansible.builtin.debug:
msg: "ERROR: {{ delete_broker_result }}"