# About loop and regex

**URL:** <https://forum.ansible.com/t/about-loop-and-regex/32902>\
**Category:** Ansible Project\
**Created:** [May 11, 2020, 6:20am UTC](https://forum.ansible.com/t/about-loop-and-regex/32902 "2020-05-11T06:20:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Umut\_Cokbilir](https://avatars.discourse-cdn.com/v4/letter/u/7cd45c/32.png) [@Umut\_Cokbilir](https://forum.ansible.com/u/Umut_Cokbilir)\
**Post date:** [May 11, 2020, 6:20am UTC](https://forum.ansible.com/t/about-loop-and-regex/32902/1 "2020-05-11T06:20:12Z")

</div>

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 }}”

 ![2.PNG](https://us1.discourse-cdn.com/ansible/original/2X/1/1dd65e493f667bac0fb1491a89b8ae37bfb5e714.png)

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 11, 2020, 7:11am UTC](https://forum.ansible.com/t/about-loop-and-regex/32902/2 "2020-05-11T07:11:24Z")

</div>

> 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 &#39;interface, vlan, description, mtu , ip address, subnet, ISIS Process, Circuit Type and QoS&#39;
> set\_fact:
> intf\_isis: &quot;\{\{ intf\_isis | default\(\[\]\) \+ item | regex\_findall\(&#39;\.\*interface\\\\s\+\(\\\\S\+\)&#39;\) \}\}&quot; 
> intf\_vlan: &quot;\{\{ intf\_vlan | default\(\[\]\) \+ item | regex\_findall\(&#39;\.\*vlan\-type\\\\s\+dot1q\\\\s\+\(\\\\S\+\)&#39;\) \}\}&quot; 
> 
> ```
> 
> # 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'  
&nbsp;&nbsp;set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intf\_isis: "{{ interface\_detail | regex\_findall('.\*interface\\s+(\\S+)') }}"

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
