Looking at "In Ansible, how to combine variables from separate files into one array?" one of the answers suggests using include_vars to get variables from several sources into one array, this is almost what I need but not quite.
I'm setting up cloudfront_logging which requires items in a awslogs_logs:
array. I'd like to be able to add to this array for the roles that I have active, so Syslog in my common role but if I have a php role, I'd like it to include the php logs.
I think I could get include_vars
to work for all roles, but I can't see how to get this to work for only the roles included in a build. So if I include the php role, include the php logs but not if it is not included.
I could, of course, include the array at the top level statically but that seems like it is architecturally a bit off as you'd expect a role to be able to deal with its' own logging.
Your roles can use a
set_fact
task to append information to a variable. For example, let's say you want roles to be able to register paths to log files in thelogfiles
fact; you could do something like this in each role:In other words, if
roles/role1/tasks
looks like this:And
roles/role2/tasks
looks like this:Then a playbook that looks like this:
Will produce this output: