The playbook currently looks that below.
---
- hosts: production
gather_facts: no
connection: local
vars:
provider:
host: "{{ inventory_hostname }}"
username: "{{ enc_username }}"
password: "{{ enc_password }}"
transport: cli
platform: cisco_nxos
tasks:
- include_vars: authentication.yml
- name: Run SHOW CDP NEI and store output
ntc_show_command:
command: "show cdp neig"
template_dir: "./ntc-templates/templates"
provider: "{{ provider }}"
register: cdp_nei
- name: Run SHOW INT STATUS and store output
ntc_show_command:
command: "show int status"
template_dir: "./ntc-templates/templates"
provider: "{{ provider }}"
register: int_stat
- name: Create interface description statements where needed
blockinfile:
dest: ./Output/cdp-output-processed
insertafter: EOF
marker: "!"
block: |
interface {{ item.local_interface }}
description ->{{ item.neighbor | regex_replace("\(.*") }}_{{ item.neighbor_interface }}
with_items: "{{ cdp_nei.response }}"
when: int_stat.response | search("{{ cdp_nei.response.item.neighbor }}"_"{{ cdp_nei.response.item.local_interface }}")