Hi all,
I'm trying to figure out a way to execute a role once per subgroup of hosts in
a single ansible-playbook run.
Here's an outline of my scenario: I want to configure multiple docker swarms.
My inventory looks something like this:
all:
hosts:
host-s1-1:
host-s1-2:
host-s2-1:
host-s2-2:
children:
swarm-1:
hosts:
host-s1-1:
host-s1-2:
swarm-2:
hosts:
host-s2-1:
host-s2-2:
swarm:
children:
swarm\-1:
swarm\-2:
I have a "docker-swarm" role which initialises a swarm, adds nodes, sets up
firewall rules, etc. My problem here is that swarm initialisation must be run
once per swarm, adding nodes is "add other nodes from my swarm group", etc.
If my play looks like this:
- hosts: swarm
become: yes
become_user: root
become_method: sudo
tasks:
- name: Execute the docker role
import_role:
name: docker
I can run ansible-playbook once limiting it to swarm-1 group, and once
limiting it to swarm-2 group. If I don't explicitly limit it to one of the
swarm group's subgroups, the play will create one docker swarm.
Is there a way to write the play to execute the role once per swarm group's
child group? Maybe group hosts using a group variable value?
Thank you!