# conditional query

**URL:** <https://forum.ansible.com/t/conditional-query/23872>\
**Category:** Ansible Project\
**Created:** [March 3, 2017, 9:32am UTC](https://forum.ansible.com/t/conditional-query/23872 "2017-03-03T09:32:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jb795333](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@jb795333](https://forum.ansible.com/u/jb795333)\
**Post date:** [March 3, 2017, 9:32am UTC](https://forum.ansible.com/t/conditional-query/23872/1 "2017-03-03T09:32:40Z")

</div>

Hello,

I am trying to enforce a conditional match to check if a VLAN is configured on a switch before applying changes

I can see that the variable is being recorded, but the match against it always results in the skipping of the task ‘interface e01’ even though the vlan number is present.

PLAY [arista] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [check VLAN] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [arista]

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [arista] =\> {

“msg”: “test: [u’VLAN Name Status Ports\n----- -------------------------------- --------- -------------------------------\n1 default active Et2, Et3\n100 VLAN0100 active Et1\n200 VLAN0200 active \n’]”

}

TASK [interface e01] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [arista]

playbook file:

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 3, 2017, 3:49pm UTC](https://forum.ansible.com/t/conditional-query/23872/2 "2017-03-03T15:49:19Z")

</div>

You need to use "test.stdout" as you did in the debug task.

---

<div class="post-metadata">

**Author:** ![jb795333](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@jb795333](https://forum.ansible.com/u/jb795333)\
**Post date:** [March 4, 2017, 10:20am UTC](https://forum.ansible.com/t/conditional-query/23872/3 "2017-03-04T10:20:08Z")

</div>

The task is still being skipped even though the VLAN 200 is present in the variable test.

Can I confirm the syntax is correct? I have written it like:

lines:

- switchport access vlan 200

- description nan

- no shutdown

parents:

- interface e01

when: “‘200’ in test.stdout”

thanks

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 4, 2017, 10:55am UTC](https://forum.ansible.com/t/conditional-query/23872/4 "2017-03-04T10:55:02Z")

</div>

> The task is still being skipped even though the VLAN 200 is present in the  
> variable test.

In the debug task use var: instead of msg: when looking at variables, it's then easier to see their structure.  
- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: test.stdout

> Can I confirm the syntax is correct? I have written it like:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lines:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- switchport access vlan 200  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- description nan  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- no shutdown  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parents:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- interface e01  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: "'200' in test.stdout"

After looking more closely at the output is seams that test.stdout is a list.  
So get the first entry you would need to use test.stdout.0
