forked from ISTI-ansible-roles/ansible-roles
54 lines
1.5 KiB
YAML
54 lines
1.5 KiB
YAML
---
|
|
- block:
|
|
- debug:
|
|
msg: "Tasks that setup the Swarm Manager nodes"
|
|
|
|
when: docker_swarm_manager | bool
|
|
tags: [ 'docker', 'docker_swarm' ]
|
|
|
|
- block:
|
|
- name: Initialize the cluster
|
|
docker_swarm:
|
|
state: present
|
|
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_hostname }}'
|
|
tags: [ 'docker', 'docker_swarm' ]
|
|
|
|
- block:
|
|
- name: Add manager nodes to the docker swarm cluster
|
|
docker_swarm:
|
|
state: join
|
|
advertise_addr: '{{ ansible_default_ipv4.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_hostname }}'
|
|
availability: '{{ docker_swarm_manager_availability }}'
|
|
|
|
when: docker_swarm_manager | bool
|
|
tags: [ 'docker', 'docker_swarm', 'docker_swarm_mgr_nodes', 'docker_swarm_mgr_availability' ]
|