conditional query

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:

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

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

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:
     var: test.stdout

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"

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