About loop and regex

Hi All,

I have a question about the loop. As You know, loopback and main interface aren’t any vlan so i need to add ‘null’ for intf_vlan’s item

How can I handle this problem?

Here is my ‘.*.yml’ part and output;
Thanks.

  • name: Extract ‘interface, vlan, description, mtu , ip address, subnet, ISIS Process, Circuit Type and QoS’
    set_fact:
    intf_isis: “{{ intf_isis | default() + item | regex_findall(‘.*interface\s+(\S+)’) }}”
    intf_vlan: “{{ intf_vlan | default() + item | regex_findall(‘.*vlan-type\s+dot1q\s+(\S+)’) }}”

intf_desc: “{{ item | regex_findall(‘.*description\s+(\S+)’) }}”

loop: “{{ interface_detail }}”

Hi All,

I have a question about the loop. As You know, loopback and main interface aren't any vlan so i need to add 'null' for
intf_vlan's item

How can I handle this problem?

*Here is my '.*.yml' part and output;*
Thanks.

\- name: Extract 'interface, vlan, description, mtu , ip address, subnet, ISIS Process, Circuit Type and QoS'
  set\_fact:
    intf\_isis: "\{\{ intf\_isis | default\(\[\]\) \+ item | regex\_findall\('\.\*interface\\\\s\+\(\\\\S\+\)'\) \}\}" 
    intf\_vlan: "\{\{ intf\_vlan | default\(\[\]\) \+ item | regex\_findall\('\.\*vlan\-type\\\\s\+dot1q\\\\s\+\(\\\\S\+\)'\) \}\}" 

# intf_desc: "{{ item | regex_findall('.*description\\s+(\\S+)') }}"
loop: "{{ interface_detail }}"

Hello Umut,

Don't use a loop here. It only complicates things in your scenario.

- name: Extract 'interface, vlan, description, mtu , ip address, subnet, ISIS Process, Circuit Type and QoS'
  set_fact:
      intf_isis: "{{ interface_detail | regex_findall('.*interface\\s+(\\S+)') }}"

Regards
          Racke