# Fetch configuration files from remote hosts

**URL:** <https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977>\
**Category:** Ansible Project\
**Created:** [October 13, 2012, 5:44am UTC](https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977 "2012-10-13T05:44:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zack\_Perry](https://avatars.discourse-cdn.com/v4/letter/z/54ee81/32.png) [@Zack\_Perry](https://forum.ansible.com/u/Zack_Perry)\
**Post date:** [October 13, 2012, 5:44am UTC](https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977/1 "2012-10-13T05:44:50Z")

</div>

I recommend you to review [http://ansible.cc/docs/modules.html#fetch](http://ansible.cc/docs/modules.html#fetch) carefully, especially the description about dest:

> dest |   
> | |   
>   
> | A directory to save the file into. For example, if the _dest_ directory is `/backup` a src file named `/etc/profile` **on host `host.example.com`, would be saved into** ` **/backup/host.example.com/etc/profile** `  
>   
>   
> |
> 
> - | - | - | - | - |

So, if your all consists of host[0:n], in your /home/user/configs, after you are done, you will see

/home/user/configs/host0/…  
/home/user/configs/host1/…  
…  
/home/user/configs/hostn/…

You may also wish to consult [http://ansible.cc/docs/playbooks2.html?highlight=with\_items#loops](http://ansible.cc/docs/playbooks2.html?highlight=with_items#loops) to get your with\_items usage right.

Regards,

Chin Fang

---

<div class="post-metadata">

**Author:** ![Dylan\_Silva](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@Dylan\_Silva](https://forum.ansible.com/u/Dylan_Silva)\
**Post date:** [October 15, 2012, 6:44pm UTC](https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977/2 "2012-10-15T18:44:27Z")

</div>

Thanks Zack, I appreciate the feedback.

While I got list of files to work, it seems that wildcard usage for file paths is not feasible. Has anyone ran into this use case? Any thoughts on how to bypass this.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 15, 2012, 6:55pm UTC](https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977/3 "2012-10-15T18:55:27Z")

</div>

> Thanks Zack, I appreciate the feedback.
> 
> While I got list of files to work, it seems that wildcard usage for file paths is not feasible. Has anyone ran into this use case? Any thoughts on how to bypass this.

Please be more specific about what “not feasible” means

---

<div class="post-metadata">

**Author:** ![Dylan\_Silva](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@Dylan\_Silva](https://forum.ansible.com/u/Dylan_Silva)\
**Post date:** [October 15, 2012, 6:59pm UTC](https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977/4 "2012-10-15T18:59:41Z")

</div>

My apologies… ☹

By not feasible, I mean, it cannot be done at all.

For instance, if I try to fetch a configuration file in a list such as the following:

- /mnt/customers/\*/appserver/domains/domain1/config/domain.xml
- /etc/nginx/conf.d/\*

Those files will not be caught.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 15, 2012, 7:01pm UTC](https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977/5 "2012-10-15T19:01:01Z")

</div>

> > Thanks Zack, I appreciate the feedback.
> > 
> > While I got list of files to work, it seems that wildcard usage for file paths is not feasible. Has anyone ran into this use case? Any thoughts on how to bypass this.
> 
> Please be more specific about what “not feasible” means

Follow up: If I infer correctly…

if you know what files you want to _PUSH_, you can use the new “with\_fileglob”, already, today, the problem is fileglob is a local thing.

If you want to fetch a lot of remote files, well, technically, you need something that returns a list of files to include first, and then to be able to feed that to with\_items.

Here’s a sketch:

tasks:

- ls: pattern=“/etc/foo/\*”  
register: ${glob\_result.list}

- fetch: src=$item dest=/somedir  
with\_items: $glob\_result

So something like a “ls” module would enable this more or less instantly, if it were to exist. (Hint hint).

It seems generally useful for other things as well.

Someone, make it so! Else it goes in the big list of 0.9 things and may not be seen again!

I think we could make the file module do this, maybe even, without much difficulty

- file: glob=“whatever/\*”

And that would allow

src=${item.path}

and would also include all the attributes about those various remote files.

Thoughts?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 15, 2012, 7:02pm UTC](https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977/6 "2012-10-15T19:02:12Z")

</div>

Indeed, there is nothing remotely evaluated about “with\_items” and giving it a list of strings.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 15, 2012, 7:15pm UTC](https://forum.ansible.com/t/fetch-configuration-files-from-remote-hosts/11977/7 "2012-10-15T19:15:41Z")

</div>

Ignore my hastily constructed earlier example, there was an error in it.

Here’s what I want to see:

- ls: pattern=“/etc/wherever/\*.txt”  
register: file\_result

- fetch: src=${item.path} dest=/somedir  
with\_items: $file\_result

Caveats/notes/random syntax theorizing:

- This should wait for 0.9, when the function to return info about a file is in module common, so we can share code with the file module.
- you can already use $last\_result to avoid the extra ‘register’ if you want.

–Michael
