-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
40 lines (39 loc) · 1.7 KB
/
playbook.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
---
- name: inventory2librenms playbook
hosts: localhost
connection: local
tasks:
- name: 'list of all librenms devices'
uri:
url: '{{ inventory2librenms_url }}/api/v0/devices?order=hostname%20DESC'
headers:
X-Auth-Token: '{{ inventory2librenms_token }}'
register: register_inventory2librenms_devices_list
- name: 'filter all hostname'
set_fact:
inventory2librenms_devices_list: "{{ register_inventory2librenms_devices_list | json_query('json.devices[*].hostname') }}"
- name: 'add new devices'
uri:
url: '{{ inventory2librenms_url }}/api/v0/devices'
method: POST
headers:
X-Auth-Token: '{{ inventory2librenms_token }}'
body: '{{ hostvars[item].inventory2librenms_body }}'
body_format: json
register: register_inventory2librenms_mew_devices
when: item not in inventory2librenms_devices_list
changed_when: "'has been added successfully' in register_inventory2librenms_mew_devices.json.status"
# failed_when: "'error' in register_inventory2librenms_mew_devices.json.status"
with_inventory_hostnames:
- all
- name: 'fix hostname is lower'
uri:
url: "{{ inventory2librenms_url }}/api/v0/devices/{{ item | lower }}/rename/{{ item }}"
method: PATCH
headers:
X-Auth-Token: '{{ inventory2librenms_token }}'
register: register_inventory2librenms_rename_devices
changed_when: "'Device has been renamed' in register_inventory2librenms_rename_devices.json.status"
when: item not in inventory2librenms_devices_list and not ( inventory2librenms_hostname_not_lower | default(false) )
with_inventory_hostnames:
- all