cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
187
Views
1
Helpful
2
Replies

Ansible Gather Facts old IOS

malcomx
Level 1
Level 1

I'm just automating my company's network using Ansible and Netbox for dynamic inventory and Source of Truth (SoT). I have a general question: how do you deal with old, unsupported IOS devices when working with Ansible? Some modules require commands like "show run | section," which my Cisco 4506 switches can't handle. Right now, I'm using a TTP template within a rescue block to format the output from "show run" on these unsupported IOS devices.

1 Accepted Solution

Accepted Solutions

Ruben Cocheno
Spotlight
Spotlight

@malcomx 

Use Netmiko to cover that gap on old devices and use TextFSM

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/

View solution in original post

2 Replies 2

While TTP templates can be helpful, Jinja2 templates offer more power and flexibility. You can use Jinja2 templates within your playbooks to process the output of "show run" on unsupported devices. You can manipulate the output of "show run" on unsupported devices. You can customize this template further to extract specific data or format the output according to your needs and use case. Hope this helps.

 

---
- hosts: cisco_ios_old
  tasks:
    - name: Get show run output
      ios_command:
        command: show run
      register: show_run_output

    - name: Process show run output with Jinja2 template
      template:
        src: show_run.j2
        dest: /tmp/processed_show_run.txt
      register: processed_output

    - name: Debug processed output (optional)
      debug:
        msg: "{{ processed_output.stdout }}"

 

# Extract the configuration for interfaces starting with 'Fa0/'
{% set interfaces = show_run_output.stdout.split('\n') %}
{% set fa_interfaces = [] %}
{% for line in interfaces %}
  {% if line.startswith('interface Fa0/') %}
    {{ line }}{% set fa_interfaces.append(line) %}
  {% endif %}
{% endfor %}

# Filter out unwanted lines and format the output
interface Fa0/0
 description: Connected to Router1
 switchport mode access
 switchport access vlan 10

interface Fa0/1
 description: Connected to ServerA
 switchport mode access
 switchport access vlan 20

{% for intf in fa_interfaces %}
  {{ intf }}{{ '\n' }}
{% endfor %}

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Ruben Cocheno
Spotlight
Spotlight

@malcomx 

Use Netmiko to cover that gap on old devices and use TextFSM

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/