deployment/ansible/roles/docker-swarm-add-manager/tasks/main.yml

19 lines
539 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
changed_when: false
- 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' ]