Register variable, get specific strings and use strings in subsequent task

Hello guys,
I am not quite sure how to describe this.
I have a simple task, which executes a shell command and register a variable.

- name: execute ovs-vsctl show command
shell: ovs-vsctl show
register: output

This will give me stdout with different ports like this:
Port “7da0c92dc […]”
Port “[479401901[…]”
[…]

But some Ports will have an error:
“could not open network device 5b574[…]”

Now I need to get all the Ports with an error (with a loop i guess (?)). Then execute a command to delete this faulty ports in subsuquent task :

- name: delete faulty ports
shell: ovs-vsctl del-port 5b574[…]

I was thinking about something like this:

- shell: ’ ovs-vsctl del-port “{{item}}” ’

with_items:
- 5b574 […]

- xxxx […]

Or what is the best way to realize this? (Probably by using a python/shell script, but it should be done with Ansible)

I have a hard time to realize this.

How can I filter for all those specific strings with faulty ports?
I probably need to save those strings in a list or something, by using a loop, right?

I would be grateful for any help / some ideas regarding the best way to proceed with this.

I don't know ovs-vsctl, but
http://www.openvswitch.org/support/dist-docs/ovs-vsctl.8.txt mentions
the option of generating output as JSON for that command.
This will probably simplify your problem.
Can you show some output with that option enabled?

Thank you for your reply.
I can’t rly get a JSON response from the command ovs-vsctl show, since it is only possible for find/list operations.

I tried to get a JSON output using a list operation, but it looks kinda strange to me… (it shows only a small part, since the output is really long)

{
“data”: [
[
[
“uuid”,
“270cedb4-f43c-4ee1-86f6-d3ac89b449fc”],
[
“set”,
],
[
“map”,
],
[
“map”,
],
[
“set”,
],
[
“set”,
],
[
“set”,
],
[
“set”,
],
[
“set”,
],
[
“set”,
],
[
“set”,
],
[
“set”,
],
“could not open network device veth1pl4194 (No such device)”,
[
“map”,