# Capture the stdout result in a variable, using regex and pass it to the next task

**URL:** <https://forum.ansible.com/t/capture-the-stdout-result-in-a-variable-using-regex-and-pass-it-to-the-next-task/29417>\
**Category:** Ansible Project\
**Created:** [January 10, 2019, 5:48pm UTC](https://forum.ansible.com/t/capture-the-stdout-result-in-a-variable-using-regex-and-pass-it-to-the-next-task/29417 "2019-01-10T17:48:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saranya\_N](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Saranya\_N](https://forum.ansible.com/u/Saranya_N)\
**Post date:** [January 10, 2019, 5:48pm UTC](https://forum.ansible.com/t/capture-the-stdout-result-in-a-variable-using-regex-and-pass-it-to-the-next-task/29417/1 "2019-01-10T17:48:19Z")

</div>

One task in my playbook produces output sample of different types like below

stdout\_lines

ex: 1

[  
“\_ \_ \_”  
“farm/dt-tk-1/env: agent\_tcp”  
]

ex: 2

[  
“\_ \_ \_”  
“test/xc-yh-1/qa: agent\_tcp”  
]

etc

I need to capture the second line regex:

test/xc-yh-1/qa

farm/dt-tk-1/env

I need to capture the above part. Im aware I can use set\_fact with regex but Im having difficulty in forming regex. Can someone kindly help

---

<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:** [January 10, 2019, 6:01pm UTC](https://forum.ansible.com/t/capture-the-stdout-result-in-a-variable-using-regex-and-pass-it-to-the-next-task/29417/2 "2019-01-10T18:01:02Z")

</div>

You don't need any regexp, just add this to your stdout\_lines

&nbsp;&nbsp;\<the variable\>.stdout\_lines.1.split(':').0

---

<div class="post-metadata">

**Author:** ![Saranya\_N](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Saranya\_N](https://forum.ansible.com/u/Saranya_N)\
**Post date:** [January 14, 2019, 12:33pm UTC](https://forum.ansible.com/t/capture-the-stdout-result-in-a-variable-using-regex-and-pass-it-to-the-next-task/29417/3 "2019-01-14T12:33:00Z")

</div>

Thankyou Kai Stian , that worked !
