# Find VLAN in a range of VLAN (930-932)

**URL:** <https://forum.ansible.com/t/find-vlan-in-a-range-of-vlan-930-932/33590>\
**Category:** Ansible Project\
**Created:** [August 11, 2020, 7:51pm UTC](https://forum.ansible.com/t/find-vlan-in-a-range-of-vlan-930-932/33590 "2020-08-11T19:51:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spiro\_Mitsialis](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Spiro\_Mitsialis](https://forum.ansible.com/u/Spiro_Mitsialis)\
**Post date:** [August 11, 2020, 7:51pm UTC](https://forum.ansible.com/t/find-vlan-in-a-range-of-vlan-930-932/33590/1 "2020-08-11T19:51:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mauricio\_Tavares](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mauricio\_Tavares](https://forum.ansible.com/u/Mauricio_Tavares)\
**Post date:** [August 11, 2020, 8:13pm UTC](https://forum.ansible.com/t/find-vlan-in-a-range-of-vlan-930-932/33590/2 "2020-08-11T20:13:55Z")

</div>

> 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.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It is probably happening because your switch does not return a  
nice list. 911-912 is a single entry in your list. I would first  
convert entries like 930-932 into 930,931,932.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 12, 2020, 8:12am UTC](https://forum.ansible.com/t/find-vlan-in-a-range-of-vlan-930-932/33590/3 "2020-08-12T08:12:49Z")

</div>

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html#network-vlan-filters](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#network-vlan-filters)

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 12, 2020, 9:03am UTC](https://forum.ansible.com/t/find-vlan-in-a-range-of-vlan-930-932/33590/4 "2020-08-12T09:03:33Z")

</div>

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:
