Fetch configuration files from remote hosts

I recommend you to review 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 to get your with_items usage right.

Regards,

Chin Fang

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.

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

My apologies… :frowning:

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.

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?

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

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