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

19 lines
539 B
YAML
Raw Normal View History

2021-12-11 16:28:17 +01:00
---
- 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
2021-12-13 11:59:34 +01:00
changed_when: false
2021-12-11 16:28:17 +01:00
- 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' ]