1234567891011121314151617181920212223242526272829303132333435363738394041 |
- ---
- - name: Add devices to librenms
- hosts:
- - DC
- - CORE
- - EDGE
- - SDA
- - MDF
- - IDF
- - PDU
- - HOSTS
- gather_facts: false
- connection: local
- tasks:
- - name: Get short hostname
- set_fact:
- hname: "{{ inventory_hostname | regex_replace('\\..*$') }}"
- - name: See if device exists in LibreNMS
- uri:
- headers:
- X-Auth-Token: "{{ librenms_auth_token }}"
- status_code:
- - 200
- - 400
- url: https://librenms.ciscolive.network/api/v0/inventory/{{ hname }}
- register: _result
- - name: See if new un-added device is reachable
- shell:
- cmd: /sbin/ping -c 2 -q -W 1 {{ inventory_hostname }}
- warn: no
- register: res
- changed_when: no
- failed_when: no
- when: _result.status == 400
- - name: Add device to LibreNMS
- command:
- cmd: /usr/bin/ssh -2 cl-monitoring.ciscolive.network /usr/local/www/librenms/addhost.php {{ hname }} ap v3 {{ snmp_user }} {{ snmp_auth_pass }} {{ snmp_priv_pass }} {{ snmp_auth_proto }} {{ snmp_priv_proto }}
- when: _result.status == 400 and "100.0% packet loss" not in res.stdout
|