Any concept of host specific files rather than role based files?

A few of my hosts need to have specific unique files copied to the host during configuration. They all share the same role but the files contents are different per host, I could go route of templating it but it would be a waste of time as I already have the static files.

So is there anything similar to the host_vars concept with respect to roles, e.g something like host_files/<host_name>/* where I can use the copy module on it?

Thanks.

copy: src=files/{{inventory_hostname}}/{{item}}
with_items:

  • file1
  • file2

you can even use fetch module to put them in per hostname dir structure, but I advise you to eventually template them.

Doh, so simple was expecting some fancy built-in feature overlooked the obvious.

Cheers.

Follow up question, copy doesn’t have a param to silently fail if source file does not exist. Out of the 20 hosts I use, only 3 have this static file that needs to be copied to it. So trying to the suggestion above, results in failures for files that do not exist.

copy: src=host_files/{{inventory_hostname}}/theFile dest…

I am leaning towards making a new role that only these 3 hosts exist in and run this single task.

No, it definitely doesn’t have such a file.

You can however use a “local_action” combined with the “stat” task to register where the local file exists, and then use “when” to skip the task.

Good suggestion, I ended up using ignore_errors on the task, your way is cleaner though.