0

I am attempting to gather data from an IOS device with Ansible, and then use the collected data to run tasks against.

I am running a task to do a show running-config command to find interfaces with a specific description:

- name: get current running-config
  ios_command:
    host: "{{ inventory_hostname }}"
    commands:
      - show running-config | i interface|description
  register: config  

Output of that task:

interface GigabitEthernet1/0/35
 description TEST PHONE
interface GigabitEthernet1/0/36
 description TEST PHONE
interface GigabitEthernet1/0/37
 description *W137
interface GigabitEthernet1/0/38
 description *W138
interface GigabitEthernet1/0/39
 description *W139
interface GigabitEthernet1/0/40
 description *W140

I am looking to grab all interface name/number that have a description starting with *. I'm using a set_fact to get that from a regex_findall():

- name: get current interfaces with special description
  set_fact: noAuthInts="{{ config.stdout[0] | regex_findall('(.*?)\n description \*(.*)')}}"

The regex works fine and gets data from the two sets. The output is seen as:

msg": [
            [
                "interface GigabitEthernet1/0/37",
                "W137"
            ],
            [
                "interface GigabitEthernet1/0/38",
                "W138"
            ],
            [
                "interface GigabitEthernet1/0/39",
                "W139"
            ],
            [
                "interface GigabitEthernet1/0/40",
                "W140"
            ],
            [
                "interface GigabitEthernet1/0/41",
                "W141"
            ],
            [
                "interface GigabitEthernet1/0/42",
                "W142"
            ],
            [
                "interface GigabitEthernet1/0/43",
                "W143"
            ]
        ]

I can't figure out how to get the two items in that list and work with them separately. I would want to run a task with ios_config to configure the interface from the interface name/number from that list and to also use that description that I gathered as well.

Is this a nested list? I've tried different variations as in:

noAuthInts.0 or noAuthInts.0.0 and noAuthInts.0.1, but do not produce what I'm looking for.

I've also tried to use the with_nested: "{{ noAuthInts }}" and iterate through that, but doesn't seem to loop correctly.

How can I grab the two pieces out of that list and use them separately?

hiddenicon
  • 551
  • 2
  • 11
  • 23

1 Answers1

0

I was able to use with_list instead of with_items or with_nested. Works fine now with list of lists. Referenced my other post: Ansible list of lists - flattening

Community
  • 1
  • 1
hiddenicon
  • 551
  • 2
  • 11
  • 23