You can create a "real" list of all the vlans that this range-list contains.
Once that is done it's trivial to do your check:


---
- hosts: localhost
  connection: local
  gather_facts: no

  vars:
    vlan_range:
"1,134,170,175,540,605,819-820,911-912,930-932,945,952,955,959-960,1200-1201,1400"

  tasks:
    - set_fact:
        vlans: "{{ vlans|default([]) |
          union(lookup('sequence', item.split('-')|first + '-' +
item.split('-')|last + ':%04d', wantlist=True ) |
          map('int')|list)  }}"
      loop: "{{ vlan_range.split(',') }}"

    - debug: var=vlans

    - debug:
        msg: "Found!"
      when: "931 in vlans"


On Wed, 12 Aug 2020 at 10:12, Dick Visser <dick.vis...@geant.org> wrote:
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#network-vlan-filters
>
> On Tue, 11 Aug 2020 at 21:51, Spiro Mitsialis <spiro.mitsia...@mcgill.ca> 
> wrote:
> >
> > Using various methods, I can get a list of VLAN on a switch port.  The list 
> > looks like the following:
> > "vlans": 
> > "1,134,170,175,540,605,819-820,911-912,930-932,945,952,955,959-960,1200-1201,1400"
> >
> > I would like to check to see if VLAN 931 is in the list.  In this case its 
> > between 930-932 in the list.  Is there a filter or function that I can use 
> > to see if its in the list?
> > Is there some other way I can get this info?
> >
> > For a single VLAN number I can use when: 'item in vlans" if in a loop but 
> > 'in" looks for exact match.
> >
> > --
> > 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-project+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/ansible-project/7fbfa960-ecea-46a7-b3b1-660f56f912dbo%40googlegroups.com.
>
>
>
> --
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwMcCOzvtJcqsrssJQaju07dTszDt8E%2BKbL8kE3ZEZtTyA%40mail.gmail.com.

Reply via email to