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

**URL:** <https://forum.ansible.com/t/register-variable-get-specific-strings-and-use-strings-in-subsequent-task/33912>\
**Category:** Ansible Project\
**Created:** [September 28, 2020, 5:44pm UTC](https://forum.ansible.com/t/register-variable-get-specific-strings-and-use-strings-in-subsequent-task/33912 "2020-09-28T17:44:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sven1](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Sven1](https://forum.ansible.com/u/Sven1)\
**Post date:** [September 28, 2020, 5:44pm UTC](https://forum.ansible.com/t/register-variable-get-specific-strings-and-use-strings-in-subsequent-task/33912/1 "2020-09-28T17:44:45Z")

</div>

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.

---

<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:** [September 28, 2020, 7:07pm UTC](https://forum.ansible.com/t/register-variable-get-specific-strings-and-use-strings-in-subsequent-task/33912/2 "2020-09-28T19:07:54Z")

</div>

I don't know ovs-vsctl, but  
[http://www.openvswitch.org/support/dist-docs/ovs-vsctl.8.txt](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?

---

<div class="post-metadata">

**Author:** ![Sven1](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Sven1](https://forum.ansible.com/u/Sven1)\
**Post date:** [September 28, 2020, 8:15pm UTC](https://forum.ansible.com/t/register-variable-get-specific-strings-and-use-strings-in-subsequent-task/33912/3 "2020-09-28T20:15:38Z")

</div>

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”,  
…
