About loop and regex

16 views
Skip to first unread message

Umut Cokbilir

unread,
May 11, 2020, 2:20:12 AM5/11/20
to Ansible Project
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


Stefan Hornburg (Racke)

unread,
May 11, 2020, 3:11:51 AM5/11/20
to ansible...@googlegroups.com
On 5/11/20 8:20 AM, Umut Cokbilir wrote:
> 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

> 2.PNG <about:invalid#zClosurez>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e7e5d6ef-eb04-4c32-aa8c-868fb0b40288%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/e7e5d6ef-eb04-4c32-aa8c-868fb0b40288%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc
Reply all
Reply to author
Forward
0 new messages