Register IOS ports based on port configurations

13 views
Skip to first unread message

Richard Lucht

unread,
Oct 21, 2020, 5:41:06 PM10/21/20
to Ansible Project
I am working on a way to register interfaces to use as a variable based on the way the port is configured.  For example I want all ports that are configured for a trunk or access vlan 10.  I have not found a way to use the jinja2 script I have.  The ansible script will go through and make a list of all the interfaces and show the configurations but that is where I am stuck.  Any help would be appreciated.

---
- name: show interfaces
  hosts: all
  connection: network_cli
  gather_facts: no
  vars:
     ansible_network_os: ios
     my_list: []

  tasks: 
  - name: show interfaces 
    ios_facts: 
      gather_subset: "interfaces"

  - name: get interface
    set_fact: 
      my_list: '{{my_list + [item]}}'
    with_items: "{{ ansible_net_interfaces }}"

  - debug:
      var: my_list

  - name: loop through 
    with_items: " {{ my_list }}"
    ios_command:
      commands: show run interface {{ item }}





{% for interface in __interface %}
  {% if interface.mode == 'trunk' %}
    int {{ interface.portName }}
    switchport trunk allowed vlan add {{ vlan_id }}
  {% endif%}
{% endfor %}
Reply all
Reply to author
Forward
0 new messages