18 lines
517 B
YAML
18 lines
517 B
YAML
---
|
|
- name: Check if swarm is already Initialized
|
|
shell: docker node ls
|
|
register: swarm_status
|
|
ignore_errors: true
|
|
|
|
- name: Check node state.
|
|
register: node_state
|
|
shell: "docker info --format '{{ '{{' }}.Swarm.LocalNodeState{{ '}}' }}'"
|
|
ignore_errors: true
|
|
|
|
- name: Add managers to the swarm
|
|
shell: >
|
|
docker swarm join
|
|
--token {{ hostvars.admin.manager_token }}
|
|
{{ hostvars.admin.ansible_host }}:2377
|
|
when: swarm_status.rc != 0 and node_state.stdout not in [ 'active', 'locked', 'error' ]
|