I’m trying to figure out how to make includable playbooks that
- Work like normal playbooks when run via ansible, running an a group of hosts
- Only run on the group of hosts from (1) that intersects with the hosts of the includer.
(Use case: I have a playbook for initializing our Jenkins slaves. Sometimes I need to run it directly to update all of the slaves to a new configuration. But sometimes I’m setting up a type of server that includes being a slave and I just need to include the role so that all servers of that type are setup correctly.)
This seems like a common use case, but I can’t find it in the documentation which makes me wonder if I have the wrong approach. Here’s what I have so far:
JenkinsSlave.yml
- name: JenkinsSlave creation
hosts: jenkinslaves:&{{hosts}}
…
BuildServer.yml
- include: JenkinsSlave.yml hosts=BuildServers
…
The above works for inclusion, but doesn’t work when I run JenkinsSlaves.yml because hosts is empty and so the intersection of JenkinsSlave and hosts is none. I’d like something like :&{{hosts|default(all)}} but that doesn’t seem to work the way I expect.
Thanks for all feedback,
Alan