Ansible Best Practices described that every role contains file directory that have all files needed by this rule.
In my case I have different roles that share the same files. But I cannot make a copy of these files in each role as there will be no one source of these files and if edit happens to one of them it will become tedious to make this change for every role.
A solution I made is to create another folder and reference it using absolute or relative path. Is this the best way of doing it?
My ansible directory look like this
play.yml
roles/
web/
tasks/
files/
common-1
common-2
other-multiple-files
role-2/
tasks/
files/
common-1
common-2
other-multiple-files
role-3/
tasks/
files/
common-2
role-4/
tasks/
files/
common-1
Best Answer
You've got two reasonably decent approaches you can try here to reduce repetition.
You could have a separate
shared-files
directory that sits as a sibling to your role folders like this:You would then reference this in the tasks with a relative file location from where the role/files folder would be:
Or alternatively to use a relative path to the folder, you could symlink things across like this:
And you can then reference the file as if it was in the role/files directory directly: