# Newbie question - parsing filenames to fetch in output of command on remote host.

**URL:** <https://forum.ansible.com/t/newbie-question-parsing-filenames-to-fetch-in-output-of-command-on-remote-host/12300>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [February 7, 2013, 5:05am UTC](https://forum.ansible.com/t/newbie-question-parsing-filenames-to-fetch-in-output-of-command-on-remote-host/12300 "2013-02-07T05:05:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VK1](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@VK1](https://forum.ansible.com/u/VK1)\
**Post date:** [February 7, 2013, 5:05am UTC](https://forum.ansible.com/t/newbie-question-parsing-filenames-to-fetch-in-output-of-command-on-remote-host/12300/1 "2013-02-07T05:05:06Z")

</div>

Hi,

I'm just starting to experiment with ansible. A simple use case (using ansible-0.9 on a RHEL 6 control node as root with a key trusted by clients)

I'm copying a source tarball from one host to a build server (RHEL6), where I'd like to su to a build user to run 'rpmbuild -tb foo.tar.gz' , redirecting stdout and stderr to a file.

The build takes a few minutes and generates a lot of output, but eventually spits out two RPMs whose names are tied to the kernel rev. The lines are fairly easy to parse:

&nbsp;&nbsp;&nbsp;Wrote: /path/to/RPM1  
&nbsp;&nbsp;&nbsp;Wrote: /path/to/RPM2

I'd like to copy the resulting RPMs back. I'd prefer not to construct the filenames ahead of time and simply use what rpmbuild spits out. If it errors out before this, those lines would be absent.

I'm experimenting with a playbook that copies the tarball and gets as far as calling the shell module to run 'su - builduser -c "rpmbuild ..."' which seems to work. Howver, the parsing and tokenizing of output, followed by fetching the resulting files back to the control node, is what I'm not clear on.

So, how can I achieve this with ansible (in the most elegant way)?

Thanks,  
VK

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [February 7, 2013, 9:16pm UTC](https://forum.ansible.com/t/newbie-question-parsing-filenames-to-fetch-in-output-of-command-on-remote-host/12300/2 "2013-02-07T21:16:55Z")

</div>

> So, how can I achieve this with ansible (in the most elegant way)?

Check out this thread:

[https://groups.google.com/forum/?fromgroups=#!topic/ansible-project/z9iIwQ9GyT8](https://groups.google.com/forum/?fromgroups=#!topic/ansible-project/z9iIwQ9GyT8)

It covers a few ways you might deal with this. One of the ways is how  
Mr. Daniel Hokka Zakrisson suggests in the thread:

Yes, the way to do it is to list the files in one action, and then use

---

<div class="post-metadata">

**Author:** ![VK1](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@VK1](https://forum.ansible.com/u/VK1)\
**Post date:** [February 11, 2013, 4:44am UTC](https://forum.ansible.com/t/newbie-question-parsing-filenames-to-fetch-in-output-of-command-on-remote-host/12300/3 "2013-02-11T04:44:53Z")

</div>

Thanks Romeo. I will give this a shot.
