Browse Source

Add support for using Ansible to push devices to LibreNMS.

Joe Clarke 4 years ago
parent
commit
fabb64eeae

+ 29 - 0
automation/cleu-ansible-n9k/add-to-librenms-playbook.yml

@@ -0,0 +1,29 @@
+---
+- name: Add devices to librenms
+  hosts:
+      - DC
+      - CORE
+      - EDGE
+      - SDA
+      - MDF
+  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: 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 hname == "dc1-ethsw-2"

+ 45 - 0
automation/cleu-ansible-n9k/add_to_librenms.py

@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+
+import argparse
+import sys
+import re
+import subprocess
+import os
+
+
+def main():
+    parser = argparse.ArgumentParser(prog=sys.argv[0], description="Add our hosts to LibreNMS")
+    parser.add_argument(
+        "--cred-file", "-c", metavar="<CREDENTIAL_FILE_PATH>", help="Path to the credential file that has vault passwords", required=True
+    )
+    parser.add_argument("--limit", metavar="<LIMIT_STRING>", help="Comma-separated list of devices or groups to add")
+    args = parser.parse_args()
+
+    os.environ["ANSIBLE_FORCE_COLOR"] = "True"
+    os.environ["ANSIBLE_HOST_KEY_CHECKING"] = "False"
+    os.environ["ANSIBLE_PERSISTENT_COMMAND_TIMEOUT"] = "300"
+
+    command = [
+        "ansible-playbook",
+        "-i",
+        "inventory/hosts",
+        "--ask-vault-pass" "-e",
+        "@{}".format(args.cred_file),
+        "-e",
+        "ansible_python_interpreter={}".format(sys.executable),
+        "add-to-librenms-playbook.yml",
+    ]
+
+    if args.switch:
+        command += ["--limit", "{}".format(args.limit)]
+
+    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    for c in iter(lambda: p.stdout.read(1), b""):
+        sys.stdout.write(c.decode("utf-8"))
+        sys.stdout.flush()
+
+    p.poll()
+
+
+if __name__ == "__main__":
+    main()

+ 5 - 0
automation/cleu-ansible-n9k/group_vars/all.yml

@@ -5,6 +5,11 @@
 # This should always be "nxos".
 ansible_network_os: nxos
 
+# SNMP variables
+snmp_auth_proto: sha
+snmp_priv_proto: des
+snmp_user: CLEUR
+
 # Core variables
 core_hsrp_vip_v4_suffix: "254"
 core_hsrp_vip_v6_suffix: "fe"

+ 94 - 13
automation/cleu-ansible-n9k/inventory/hosts

@@ -1,30 +1,78 @@
 [NXOS_DC1]
-10.127.0.249 core_svi_v4_suffix="249" core_svi_v6_suffix="f9" core_hsrp_priority="105"
-10.127.0.250 core_svi_v4_suffix="250" core_svi_v6_suffix="fa" core_hsrp_priority="104"
+dc1-ethsw-1.ciscolive.network core_svi_v4_suffix="249" core_svi_v6_suffix="f9" core_hsrp_priority="105"
+dc1-ethsw-2.ciscolive.network core_svi_v4_suffix="250" core_svi_v6_suffix="fa" core_hsrp_priority="104"
 
 [NXOS_DC2]
-10.127.0.247 core_svi_v4_suffix="247" core_svi_v6_suffix="f7" core_hsrp_priority="103"
-10.127.0.248 core_svi_v4_suffix="248" core_svi_v6_suffix="f8" core_hsrp_priority="102"
+dc2-ethsw-1.ciscolive.network core_svi_v4_suffix="247" core_svi_v6_suffix="f7" core_hsrp_priority="103"
+dc2-ethsw-2.ciscolive.network core_svi_v4_suffix="248" core_svi_v6_suffix="f8" core_hsrp_priority="102"
+
+[EDGE1]
+core1-edge.ciscolive.network
+
+[EDGE2]
+core2-edge.ciscolive.network
+
+[TS_DC1]
+dc1-ts.ciscolive.network
+
+[TS_DC2]
+dc2-ts.ciscolive.network
+
+[NETAPP_DC1]
+cl-emea-noc-mcc-dc1.ciscolive.network
+
+[NETAPP_DC2]
+cl-emea-noc-mcc-dc2.ciscolive.network
+
+[SDA]
+fusion-005-mdf-a.ciscolive.network
+fusion-005-mdf-b.ciscolive.network
+
+[MDF]
+003-mdf-a.ciscolive.network
+003-mdf-b.ciscolive.network
+004-mdf-a.ciscolive.network
+004-mdf-b.ciscolive.network
+005-mdf-a.ciscolive.network
+005-mdf-b.ciscolive.network
+006-mdf-a.ciscolive.network
+006-mdf-b.ciscolive.network
+007-mdf-a.ciscolive.network
+007-mdf-b.ciscolive.network
+008-mdf-a.ciscolive.network
+008-mdf-b.ciscolive.network
+
+[CORE1]
+core1-l3c.ciscolive.network
+core1-ts.ciscolive.network
+core1-wa.ciscolive.network
+core1-wb.ciscolive.network
+
+[CORE2]
+core2-l3c.ciscolive.network
+core2-ts.ciscolive.network
+core2-wa.ciscolive.network
+core2-wb.ciscolive.network
 
 [MCC_DC1]
-10.127.253.25
-10.127.253.26
+dc1-mccsw-1.ciscolive.network
+dc1-mccsw-2.ciscolive.network
 
 [MCC_DC2]
-10.127.254.25
-10.127.254.26
+dc2-mccsw-1.ciscolive.network
+dc2-mccsw-2.ciscolive.network
 
 [UCS_DC1]
-10.127.253.42
+dc1-ucsmini.ciscolive.network
 
 [UCS_DC2]
-10.127.254.42
+dc2-ucsmini.ciscolive.network
 
 [HX_DC1]
-10.127.253.72
+dc1-hx-ucs.ciscolive.network
 
 [HX_DC2]
-10.127.254.72
+dc2-hx-ucs.ciscolive.network
 
 [MCC:children]
 MCC_DC1
@@ -38,6 +86,9 @@ tacacs_vrf="management"
 UCS_DC1
 UCS_DC2
 
+[UCS:vars]
+snmp_priv_proto="aes"
+
 [HX:children]
 HX_DC1
 HX_DC2
@@ -58,17 +109,47 @@ vnic_templates='["hx-vm-network-a", "hx-vm-network-b"]'
 multicast_policy=""
 vnic_templates='["vnic-vlans-a", "vnic-vlans-b"]'
 
+[CORE:children]
+CORE1
+CORE2
+
+[EDGE:children]
+EDGE1
+EDGE2
+
+[NETAPP:children]
+NETAPP_DC1
+NETAPP_DC2
+
+[TS_DC:children]
+TS_DC1
+TS_DC2
+
 [vCenter]
-10.100.252.11
+cl-vcenter.ad.ciscolive.network
 
 [DC1:children]
 NXOS_DC1
 UCS_DC1
 HX_DC1
 vCenter
+TS_DC1
+MCC_DC1
+NETAPP_DC1
 
 [DC2:children]
 NXOS_DC2
 UCS_DC2
 HX_DC2
 vCenter
+TS_DC2
+MCC_DC2
+NETAPP_DC2
+
+[DC:children]
+NXOS
+UCS
+HX
+TS_DC
+NETAPP
+MCC