add-to-librenms-playbook.yml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ---
  2. - name: Add devices to librenms
  3. hosts:
  4. - DC
  5. - CORE
  6. - EDGE
  7. - SDA
  8. - MDF
  9. - IDF
  10. - PDU
  11. - HOSTS
  12. gather_facts: false
  13. connection: local
  14. tasks:
  15. - name: Get short hostname
  16. set_fact:
  17. hname: "{{ inventory_hostname | regex_replace('\\..*$') }}"
  18. - name: See if device exists in LibreNMS
  19. uri:
  20. headers:
  21. X-Auth-Token: "{{ librenms_auth_token }}"
  22. status_code:
  23. - 200
  24. - 400
  25. url: https://librenms.ciscolive.network/api/v0/inventory/{{ hname }}
  26. register: _result
  27. - name: See if new un-added device is reachable
  28. shell:
  29. cmd: /sbin/ping -c 2 -q -W 1 {{ inventory_hostname }}
  30. warn: no
  31. register: res
  32. changed_when: no
  33. failed_when: no
  34. when: _result.status == 400
  35. - name: Add device to LibreNMS
  36. command:
  37. 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 }}
  38. when: _result.status == 400 and "100.0% packet loss" not in res.stdout