# How to get and parse the output from target hosts

**URL:** <https://forum.ansible.com/t/how-to-get-and-parse-the-output-from-target-hosts/22546>\
**Category:** Ansible Project\
**Created:** [September 14, 2016, 5:40pm UTC](https://forum.ansible.com/t/how-to-get-and-parse-the-output-from-target-hosts/22546 "2016-09-14T17:40:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorg\_Kastning](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Jorg\_Kastning](https://forum.ansible.com/u/Jorg_Kastning)\
**Post date:** [September 14, 2016, 5:40pm UTC](https://forum.ansible.com/t/how-to-get-and-parse-the-output-from-target-hosts/22546/1 "2016-09-14T17:40:42Z")

</div>

Hello,

I would like to write a playbook to install Red Hat Security Advisory on my hosts. The idea is to put the published information about the advisories with their Numbers (e.g. RHSA-2016:1234) in a variable and run the following playbook on all hosts:

`

---

<div class="post-metadata">

**Author:** ![Alexander\_H\_Laughlin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_H\_Laughlin](https://forum.ansible.com/u/Alexander_H_Laughlin)\
**Post date:** [September 14, 2016, 9:54pm UTC](https://forum.ansible.com/t/how-to-get-and-parse-the-output-from-target-hosts/22546/2 "2016-09-14T21:54:54Z")

</div>

I believe something like:

`

- name: Reboot if packages were updated  
command: reboot NOW  
when: “‘Complete!’ in yumoutput”  
`

would do the trick.

[http://docs.ansible.com/ansible/playbooks\_conditionals.html#applying-when-to-roles-and-includes](http://docs.ansible.com/ansible/playbooks_conditionals.html#applying-when-to-roles-and-includes)

[http://stackoverflow.com/questions/30533372/run-an-ansible-task-only-when-the-hostname-contains-a-string](http://stackoverflow.com/questions/30533372/run-an-ansible-task-only-when-the-hostname-contains-a-string)

That is assuming that you don’t have the string ‘Complete!’ turning up anywhere else in the output.

---

<div class="post-metadata">

**Author:** ![Jorg\_Kastning](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Jorg\_Kastning](https://forum.ansible.com/u/Jorg_Kastning)\
**Post date:** [September 15, 2016, 8:53am UTC](https://forum.ansible.com/t/how-to-get-and-parse-the-output-from-target-hosts/22546/3 "2016-09-15T08:53:02Z")

</div>

Hi Alexander,

you put me in the right direction. I’d like to give a short example for my solution:

`
