ansible-role-docker/tasks/swarm_mgr.yml

55 lines
1.6 KiB
YAML
Raw Normal View History

2020-08-11 20:01:36 +02:00
---
- block:
- debug:
msg: "Tasks that set up the Swarm Manager nodes"
2020-08-11 20:01:36 +02:00
when: docker_swarm_manager | bool
tags: [ 'docker', 'docker_swarm' ]
- block:
- name: Initialize the cluster
docker_swarm:
state: present
2022-02-22 00:02:53 +01:00
advertise_addr: '{{ docker_swarm_manager_advertise_address }}'
2020-08-11 20:01:36 +02:00
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 }}'
2020-08-11 20:01:36 +02:00
tags: [ 'docker', 'docker_swarm' ]
- block:
- name: Add some manager nodes to the docker swarm cluster
2020-08-11 20:01:36 +02:00
docker_swarm:
state: join
2022-02-21 23:57:43 +01:00
advertise_addr: '{{ docker_swarm_node_advertise_address }}'
2020-08-11 20:01:36 +02:00
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 }}'
2020-08-11 20:01:36 +02:00
availability: '{{ docker_swarm_manager_availability }}'
when: docker_swarm_manager | bool
tags: [ 'docker', 'docker_swarm', 'docker_swarm_mgr_nodes', 'docker_swarm_mgr_availability' ]