From 6e755aaaf45c6945db1137672b4ead71d4d934ab Mon Sep 17 00:00:00 2001 From: Jason King Date: Wed, 1 May 2024 17:07:48 -0700 Subject: [PATCH] Updates for parsing CDP data with pyATS --- playbooks/cml_update_lab.yml | 38 +++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/playbooks/cml_update_lab.yml b/playbooks/cml_update_lab.yml index 3a431b2..7ad34b1 100644 --- a/playbooks/cml_update_lab.yml +++ b/playbooks/cml_update_lab.yml @@ -6,6 +6,7 @@ roles: - ciscops.mdd.nso vars: + method: nso_parse start_from: 2 layout: kamada_kawai scale: 500 @@ -39,16 +40,35 @@ vasiright(\d+): vasiright\1 tasks: - - name: Get CDP data - ansible.builtin.include_role: - name: ciscops.mdd.nso - tasks_from: exec_command - vars: - nso_exec_command: show cdp neighbors + - when: method == "nso_parse" + block: + - name: Get CDP data via nso_parse and PyATS + ansible.builtin.include_role: + name: ciscops.mdd.check + tasks_from: nso_parse + vars: + check_command: "show cdp neighbors" + + - name: Build CDP data table + ansible.builtin.set_fact: + cdp_data: "{{ {'hostname': inventory_hostname, 'tags': tags if tags is defined else {}, 'cdp': parsed_output.cdp} }}" - - name: Build CDP data table - ansible.builtin.set_fact: - cdp_data: "{{ {'hostname': inventory_hostname, 'tags': tags if tags is defined else {}, 'cdp': nso_command_output} }}" + - when: method == "cli_parse" + block: + - name: Get CDP data via cli_parse and PyATS + ansible.utils.cli_parse: + command: "{{ parser_command }}" + parser: + name: ansible.netcommon.pyats + command: "{{ parser_command | default(omit) }}" + connection: network_cli + vars: + parser_command: "show cdp neighbor" + register: parse_results + + - name: Build CDP data table + ansible.builtin.set_fact: + cdp_data: "{{ {'hostname': inventory_hostname, 'tags': tags if tags is defined else {}, 'cdp': parse_results.parsed.cdp} }}" - name: Generate topology and mapping file run_once: True