Simple terraform+ansible configuration to quickly spin up a development Docker swarm on my homeserver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
840 B

- name: get node status
command: "docker info -f '{{ '{{' }}.Swarm.LocalNodeState{{ '}}' }}'"
register: local_node_state
changed_when: false
- name: initialize swarm
when: local_node_state.stdout == "inactive"
command: "docker swarm init --advertise-addr {{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
- name: get join token for managers
command: "docker swarm join-token -q manager"
register: token_managers
changed_when: false
- name: set join token for managers as host fact
swarm_token_managers: "{{ token_managers.stdout }}"
- name: get join token for workers
command: "docker swarm join-token -q worker"
register: token_workers
changed_when: false
- name: set join token for workers as host fact
swarm_token_workers: "{{ token_workers.stdout }}"