copy action with_fileglob always skips files in 1.2

The pattern mentioned here is failing for me in 1.2:
http://www.ansibleworks.com/docs/playbooks2.html#lookup-plugins-accessing-outside-data

I believe my playbook worked in 1.1, but every task that uses copy with_fileglob always says it is “skipping:” these tasks with no other output in verbose mode (-vvv).
This happens regardless of whether I use asterisks or exact filenames in the fileglob or whether I use $item or {{ item }}. Did I miss a setting or change in the syntax?

Examples:

  • name: “nagios config: servers”
    copy: src={{ item }} dest=/etc/nagios3/servers/ owner=root group=root mode=644
    with_fileglob:

  • roles/admin/files/etc/nagios3/servers/.
    notify:

  • restart nagios

  • name: bash env dotfiles
    copy: src={{ item }} dest=/home/username/ owner=username group=username mode=744
    with_fileglob:

  • roles/admin/files/home/username/.env_file

OR

  • name: bash env dotfiles
    copy: src={{ item }} dest=/home/username/ owner=username group=username mode=744
    with_fileglob:
  • roles/admin/files/home/username/*

Dave:

This bit me the other day, so I submitted a doc patch which got accepted, from the link you sent:

Note

When using with_fileglob or with_file with Roles, if you specify a relative path (e.g., ./foo), Ansible resolves the path relative to the roles/<rolename>/files directory.

Zap the “roles/admin/files/” from your path, and it should work, e.g.:

with_fileglob:

  • etc/nagios3/servers/.

Lorin

Lorin,

Thank you so much, that worked!

Also, for others who may read this, this is also the case with the src= attribute of copy if you are specifying the full path to a file. In other words, these both worked for me:

copy: src=roles/admin/files/etc/apache2/sites-available/default-ssl dest=/etc/apache2/sites-available/ owner=root group=root mode=644

AND

copy: src=etc/apache2/sites-available/default-ssl dest=/etc/apache2/sites-available/ owner=root group=root mode=644

Slight clarification is that it looks in the “files/” directory if and only if the files directory exists.

But yes!

Is there a similar default path in the templates module?

I have a template with a relative path and ansible is assuming it is in the templates dir.

  • name: coord config
    template: src=opt/app/conf/coord.cfg.template dest=/opt/app/conf/coord.cfg owner=username group= username mode=644 backup=no

Running this produces an error:

input file not found at /path/to/app/templates/opt/app/conf/coord.cfg.template

the file is actually store in

roles/app/files/opt/app/conf/coord.cfg.template

I now realize templates may be a better place for it than files, but I’m still curious about the behavior. As far as I have found in my searches, this is undocumented, but perhaps I missed it?

Yes, see this: http://www.ansibleworks.com/docs/bestpractices.html#directory-layout.

That makes sense as a best practice. May I suggest documenting more clearly that these are also the defaults that ansible uses in relative paths?
If that is documented anywhere, I had a hard time finding it.

Yes, upgrades to the documentation are welcome! You may send in patches to the github repo at docsite/latest/rst/*.rst.

Very cool. Thank you and will do!