I’m looking for some tips on the best way to store a variable persistently across all hosts or multiple plays.
I am attempting to create a docker swarm manager using something similar to this:
hosts: swarm-init
gather_facts: no
tasks:
shell: docker swarm init
shell: docker swarm join-token -q manager
register: manager
shell: docker swarm join-token -q worker
register: worker
I would run this play once and don’t have that logic built yet but I have not been able to find a method of storing {{ worker }} in a variable so that I could join the swarm from another host in another play. Any advice?
This works just fine when I set_fact for “manager” on the desired host.
1.
mtoken: “{{ hostvars[‘myhost.net’][‘manager’] | replace(‘[u’, ‘’) | replace(‘]’, ‘’)}}”
but I need to be able to get the name of the single host that is in the group passed with something like this. Perhaps i need to step back and regroup and go about this in a different way. Any tips would be appreciated.