34 lines
970 B
YAML
34 lines
970 B
YAML
|
# https://github.com/ruanbekker/ansible-docker-swarm/blob/master/roles/docker-swarm-init/tasks/main.yml
|
||
|
---
|
||
|
# Basically we put the exit code in the variable and use it later
|
||
|
- name: Check if swarm has already been initialized.
|
||
|
shell: docker node ls
|
||
|
register: swarm_status
|
||
|
ignore_errors: true
|
||
|
changed_when: false
|
||
|
|
||
|
- name: Initialize Docker Swarm.
|
||
|
shell: >
|
||
|
docker swarm init
|
||
|
--advertise-addr={{ hostvars[inventory_hostname]['ansible_host'] }}:2377
|
||
|
when: swarm_status.rc != 0
|
||
|
run_once: true
|
||
|
|
||
|
- name: Get manager join token.
|
||
|
shell: docker swarm join-token --quiet manager
|
||
|
register: manager_token
|
||
|
changed_when: false
|
||
|
|
||
|
- name: Store manager join token as fact.
|
||
|
set_fact:
|
||
|
manager_token: "{{ manager_token.stdout }}"
|
||
|
|
||
|
- name: Get worker join token.
|
||
|
shell: docker swarm join-token --quiet worker
|
||
|
register: worker_token
|
||
|
changed_when: false
|
||
|
|
||
|
- name: Store worker join token as fact.
|
||
|
set_fact:
|
||
|
worker_token: "{{ worker_token.stdout }}"
|