From 4ddf246a58eaaf6776cb2eea493a08c689bdcdd7 Mon Sep 17 00:00:00 2001 From: Ivan Pepelnjak Date: Sat, 7 Oct 2017 19:03:07 +0000 Subject: [PATCH] Changed the playbooks to support napalm-ansible 0.7.0. Also changed 'os' fact to 'ansible_os' to make the playbooks consistent with other examples. --- LLDP-to-Graph/LLDP-test.yml | 2 +- LLDP-to-Graph/LLDP-to-Graph.yml | 2 +- LLDP-to-Graph/README.md | 16 ++++++++++++++++ LLDP-to-Graph/ansible.cfg | 2 +- LLDP-to-Graph/hosts | 8 ++++---- LLDP-to-Graph/links-fix.j2 | 2 +- LLDP-to-Graph/links.j2 | 2 +- LLDP-to-Graph/neighbors.j2 | 2 +- LLDP-to-Graph/simple-graph.j2 | 2 +- OSPF-Deployment/hosts.fqdn | 9 +++++++++ 10 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 OSPF-Deployment/hosts.fqdn diff --git a/LLDP-to-Graph/LLDP-test.yml b/LLDP-to-Graph/LLDP-test.yml index dd4430a..59e6839 100644 --- a/LLDP-to-Graph/LLDP-test.yml +++ b/LLDP-to-Graph/LLDP-test.yml @@ -6,7 +6,7 @@ hostname: "{{ansible_host|default(inventory_hostname)}}" username: "{{ansible_user}}" password: "{{ansible_ssh_pass}}" - dev_os: "{{os}}" + dev_os: "{{ansible_os}}" optional_args: port: "{{api_port|default(ansible_port)|default(22)}}" filter: diff --git a/LLDP-to-Graph/LLDP-to-Graph.yml b/LLDP-to-Graph/LLDP-to-Graph.yml index 16d32db..c2ed3d3 100644 --- a/LLDP-to-Graph/LLDP-to-Graph.yml +++ b/LLDP-to-Graph/LLDP-to-Graph.yml @@ -6,7 +6,7 @@ hostname: "{{ansible_host|default(inventory_hostname)}}" username: "{{ansible_user}}" password: "{{ansible_ssh_pass}}" - dev_os: "{{os}}" + dev_os: "{{ansible_os}}" optional_args: port: "{{api_port|default(ansible_port)|default(22)}}" filter: diff --git a/LLDP-to-Graph/README.md b/LLDP-to-Graph/README.md index b8e682c..6596ea5 100644 --- a/LLDP-to-Graph/README.md +++ b/LLDP-to-Graph/README.md @@ -3,6 +3,22 @@ The *LLDP-to-Graph* Ansible playbook uses LLDP neighbor data collected with *napalm_get_facts* Ansible module to generate network diagram in *Graphviz* .dot file format. +## Installation guide + +The playbooks were tested with these versions of Ansible and NAPALM: + +* Ansible 2.4 +* napalm 1.2.0 (or greater) +* napalm-ansible 0.7.0 (or greater) + +Notes: + +* The playbooks have been updated to work with Ansible 2.4 and will not work + with previous versions of Ansible +* Run `napalm-ansible` to find path to your distribution of NAPALM + and update ansible.cfg accordingly +* The graph-generation playbook doesn't work correctly with Cisco IOS because NAPALM reports different interface names in interface facts and LLDP neighbor facts + ## Usage * Create your inventory file. The current **hosts** file uses vEOS leaf-and-spine topology. Set IP addresses, usernames, passwords and ports in the inventory file. diff --git a/LLDP-to-Graph/ansible.cfg b/LLDP-to-Graph/ansible.cfg index 663d733..5be1c86 100644 --- a/LLDP-to-Graph/ansible.cfg +++ b/LLDP-to-Graph/ansible.cfg @@ -3,4 +3,4 @@ inventory=./hosts gathering=explicit retry_files_enabled=false transport=local -library=napalm-ansible/library +library=/usr/local/lib/python2.7/dist-packages/napalm_ansible \ No newline at end of file diff --git a/LLDP-to-Graph/hosts b/LLDP-to-Graph/hosts index 320c401..f5f8fb6 100644 --- a/LLDP-to-Graph/hosts +++ b/LLDP-to-Graph/hosts @@ -1,4 +1,4 @@ -spine-1 ansible_host=10.0.2.2 ansible_port=20001 api_port=21001 os=eos ansible_user=admin ansible_ssh_pass=admin -spine-2 ansible_host=10.0.2.2 ansible_port=20002 api_port=21002 os=eos ansible_user=admin ansible_ssh_pass=admin -leaf-1 ansible_host=10.0.2.2 ansible_port=20003 api_port=21003 os=eos ansible_user=admin ansible_ssh_pass=admin -leaf-2 ansible_host=10.0.2.2 ansible_port=20004 api_port=21004 os=eos ansible_user=admin ansible_ssh_pass=admin +spine-1 ansible_host=10.0.2.2 ansible_port=20001 api_port=21001 ansible_os=eos ansible_user=admin ansible_ssh_pass=admin +spine-2 ansible_host=10.0.2.2 ansible_port=20002 api_port=21002 ansible_os=eos ansible_user=admin ansible_ssh_pass=admin +leaf-1 ansible_host=10.0.2.2 ansible_port=20003 api_port=21003 ansible_os=eos ansible_user=admin ansible_ssh_pass=admin +leaf-2 ansible_host=10.0.2.2 ansible_port=20004 api_port=21004 ansible_os=eos ansible_user=admin ansible_ssh_pass=admin diff --git a/LLDP-to-Graph/links-fix.j2 b/LLDP-to-Graph/links-fix.j2 index 612d682..8bf79ae 100644 --- a/LLDP-to-Graph/links-fix.j2 +++ b/LLDP-to-Graph/links-fix.j2 @@ -1,5 +1,5 @@ {% for local in play_hosts %} -{% for ifname,lldp in hostvars[local].lldp_neighbors|dictsort if lldp|length > 0 %} +{% for ifname,lldp in hostvars[local].napalm_lldp_neighbors|dictsort if lldp|length > 0 %} {% for n in lldp if local < n.hostname or n.hostname not in play_hosts %} {{local}}:{{ifname}} -- {{n.hostname}}:{{n.port}} {% endfor %} diff --git a/LLDP-to-Graph/links.j2 b/LLDP-to-Graph/links.j2 index 1709973..6843470 100644 --- a/LLDP-to-Graph/links.j2 +++ b/LLDP-to-Graph/links.j2 @@ -1,5 +1,5 @@ {% for local in play_hosts %} -{% for ifname,lldp in hostvars[local].lldp_neighbors|dictsort if lldp|length > 0 %} +{% for ifname,lldp in hostvars[local].napalm_lldp_neighbors|dictsort if lldp|length > 0 %} {% for n in lldp if local < n.hostname %} {{local}}:{{ifname}} -- {{n.hostname}}:{{n.port}} {% endfor %} diff --git a/LLDP-to-Graph/neighbors.j2 b/LLDP-to-Graph/neighbors.j2 index 73ec8d6..4fa444f 100644 --- a/LLDP-to-Graph/neighbors.j2 +++ b/LLDP-to-Graph/neighbors.j2 @@ -1,5 +1,5 @@ {% for local in play_hosts %} -{% for ifname,lldp in hostvars[local].lldp_neighbors|dictsort if lldp|length > 0 %} +{% for ifname,lldp in hostvars[local].napalm_lldp_neighbors|dictsort if lldp|length > 0 %} {% for n in lldp %} {{local}}:{{ifname}} -- {{n.hostname}}:{{n.port}} {% endfor %} diff --git a/LLDP-to-Graph/simple-graph.j2 b/LLDP-to-Graph/simple-graph.j2 index 1d26154..921283d 100644 --- a/LLDP-to-Graph/simple-graph.j2 +++ b/LLDP-to-Graph/simple-graph.j2 @@ -3,7 +3,7 @@ graph network { "{{local}}" [shape=box] {% endfor %} {% for local in play_hosts %} -{% for ifname,lldp in hostvars[local].lldp_neighbors|dictsort if lldp|length > 0 %} +{% for ifname,lldp in hostvars[local].napalm_lldp_neighbors|dictsort if lldp|length > 0 %} {% for n in lldp if local < n.hostname or n.hostname not in play_hosts %} "{{local}}" -- "{{n.hostname}}"; {% endfor %} diff --git a/OSPF-Deployment/hosts.fqdn b/OSPF-Deployment/hosts.fqdn new file mode 100644 index 0000000..332a0ac --- /dev/null +++ b/OSPF-Deployment/hosts.fqdn @@ -0,0 +1,9 @@ +# +# Auto-generated inventory file +# +E1.virl.info ansible_host=172.16.1.110 ansible_os=ios ansible_user=cisco ansible_ssh_pass=cisco +E2.virl.info ansible_host=172.16.1.111 ansible_os=ios ansible_user=cisco ansible_ssh_pass=cisco +E3.virl.info ansible_host=172.16.1.120 ansible_os=ios ansible_user=cisco ansible_ssh_pass=cisco +E4.virl.info ansible_host=172.16.1.121 ansible_os=ios ansible_user=cisco ansible_ssh_pass=cisco +PE1.virl.info ansible_host=172.16.1.112 ansible_os=ios ansible_user=cisco ansible_ssh_pass=cisco +PE2.virl.info ansible_host=172.16.1.122 ansible_os=ios ansible_user=cisco ansible_ssh_pass=cisco