ansible-role-docker/tasks/swarm_mgr.yml

55 lines
1.6 KiB
YAML

---
- block:
- debug:
msg: "Tasks that set up the Swarm Manager nodes"
when: docker_swarm_manager | bool
tags: [ 'docker', 'docker_swarm' ]
- block:
- name: Initialize the cluster
docker_swarm:
state: present
advertise_addr: '{{ +docker_swarm_manager_advertise_address }}'
when:
- docker_swarm_manager | bool
- docker_swarm_manager_main_node | bool
tags: [ 'docker', 'docker_swarm', 'docker_swarm_init' ]
- block:
- name: Get swarm status information
docker_swarm:
state: inspect
register: swarm_info_data
- name: Get the swarm manager token
set_fact:
docker_swarm_mgr_token: '{{ swarm_info_data.swarm_facts.JoinTokens.Manager }}'
cacheable: True
when: docker_swarm_manager
delegate_to: '{{ docker_swarm_manager_main_node_address }}'
tags: [ 'docker', 'docker_swarm' ]
- block:
- name: Add some manager nodes to the docker swarm cluster
docker_swarm:
state: join
advertise_addr: '{{ docker_swarm_node_advertise_address }}'
join_token: '{{ docker_swarm_mgr_token }}'
remote_addrs: [ '{{ docker_swarm_manager_main_node_hostname }}:2377' ]
when:
- docker_swarm_manager | bool
- not docker_swarm_manager_main_node | bool
tags: [ 'docker', 'docker_swarm', 'docker_swarm_mgr_nodes' ]
- block:
- name: Set the swarm manager nodes availability. Default 'drain'
docker_node:
hostname: '{{ ansible_fqdn }}'
availability: '{{ docker_swarm_manager_availability }}'
when: docker_swarm_manager | bool
tags: [ 'docker', 'docker_swarm', 'docker_swarm_mgr_nodes', 'docker_swarm_mgr_availability' ]