@chris I think it’s treating his VLAN as a string since he’s entering it through prompt, not as a var.
So: search: ".*{{ VLAN }} VLAN{{ '%04d' | format(VLAN|int) }} active.*"
should fix the typing.
That said, @Cysco_Colloh, it looks like VLAN0054
is the name field from the output? If that’s the case, it may be coincidence that it is “VLAN” + <0-padded-54>. Unless you can say with confidence that all of the names of your vlans are consistent (or even better, programmatic), then I can’t say my search string will be consistent.
On another note, while we have spent a lot of effort trying to help you achieve the process you’re going for, I can’t help but wonder if there’s an easier way to do all of this if you can change your approach.
Ansible is meant to be idempotent, where you can run the same playbook over and over again and never do the same thing twice. Obviously you want to do that with your vlans by making sure they’re unique to your switches. You could define the vlans in your host_vars for each switch, and then have the playbook only configure the vlans defined per switch. Depending on how many switches and vlans you have, that might be tedius, but at least then you would know the switches would get the vlans you want them to have. You could create the list of vlans you want first, gather facts about what vlans are there after they’re configured, and remove any extra vlans that weren’t in the original list (or at least notify you/network admins that there are ‘rogue’ vlans on a given switch).