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

18 lines
550 B
YAML
Raw Normal View History

2021-12-11 16:28:17 +01:00
---
- 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 worker to swarm.
register: join_cmd
shell: >
docker swarm join
--token {{ hostvars.admin.worker_token }}
{{ hostvars.admin.ansible_host }}:2377
# 0 means it was successfully added, 1 means it's already in the swarm.
failed_when: join_cmd.rc != 0
changed_when: join_cmd.rc == 0
when: node_state.stdout not in [ 'active', 'locked', 'error' ]