I have a role, let's call it apache2. The role installs apache2 and all of its dependencies.
Now I have two machines, let's call them M1 and M2. Both M1 and M2 need to have apache2 installed. However, each of them needs their own set of files installed into the web root. So M1.yml looks like:
--- - hosts: M1 - role: apache2
M2.yml looks like:
--- - hosts: M2 - role: apache2
Obviously I can't just put the files into the role's
files directory, as they are different for each. Options of which I am aware:
- Create a
post_taskssection for each playbook that copies over the necessary files and configures the server.
- Create a
copy_filesrole that takes the files as a variable
The reason I don't like #1 is because I might have a bunch of similar roles (apache2, nginx, ftp, etc.) each of which requires installation and files to be copied over. I'd like to keep each "together", meaning that the "install apache2" and "copy apache2 files to guest" tasks are both specified near each other in the file.
The reason I don't like #2 is because it seems heavyweight to basically just wrap a task as a role.
Is there another option I'm not thinking of? And of the available options, which is considered best practice?