2020-08-11 20:01:36 +02:00
|
|
|
---
|
|
|
|
- block:
|
|
|
|
- debug:
|
|
|
|
msg: "Tasks that setup the Swarm worker nodes"
|
|
|
|
|
|
|
|
when: docker_swarm_node | bool
|
|
|
|
tags: [ 'docker', 'docker_swarm' ]
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- name: Get swarm status information
|
|
|
|
docker_swarm:
|
|
|
|
state: inspect
|
|
|
|
register: swarm_info_data
|
|
|
|
|
|
|
|
- name: Get the swarm worker node token
|
|
|
|
set_fact:
|
|
|
|
docker_swarm_worker_token: '{{ swarm_info_data.swarm_facts.JoinTokens.Worker }}'
|
|
|
|
cacheable: True
|
|
|
|
|
|
|
|
when: docker_swarm_node | bool
|
|
|
|
delegate_to: '{{ docker_swarm_manager_main_node_hostname }}'
|
|
|
|
tags: [ 'docker', 'docker_swarm' ]
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- name: Add worker nodes to the docker swarm cluster
|
|
|
|
docker_swarm:
|
|
|
|
state: join
|
|
|
|
advertise_addr: '{{ ansible_default_ipv4.address }}'
|
|
|
|
join_token: '{{ docker_swarm_worker_token }}'
|
|
|
|
remote_addrs: [ '{{ docker_swarm_manager_main_node_hostname }}:2377' ]
|
|
|
|
|
|
|
|
when: docker_swarm_node | bool
|
|
|
|
tags: [ 'docker', 'docker_swarm', 'docker_swarm_worker_nodes' ]
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- name: Set the swarm nodes availability. Default 'active'
|
|
|
|
docker_node:
|
|
|
|
hostname: '{{ ansible_hostname }}'
|
|
|
|
availability: '{{ docker_swarm_node_availability }}'
|
|
|
|
|
|
|
|
when: docker_swarm_node | bool
|
|
|
|
delegate_to: '{{ docker_swarm_manager_main_node_hostname }}'
|
|
|
|
tags: [ 'docker', 'docker_swarm', 'docker_swarm_worker_nodes', 'docker_swarm_worker_nodes_availability' ]
|
2020-09-17 19:19:17 +02:00
|
|
|
|
|
|
|
- name: Manage labels
|
|
|
|
block:
|
|
|
|
- name: Manage the swarm nodes labels
|
|
|
|
docker_node:
|
|
|
|
hostname: '{{ ansible_hostname }}'
|
|
|
|
labels:
|
2020-10-26 14:44:55 +01:00
|
|
|
"{{ item.key }}": '{{ item.value }}'
|
2020-09-17 19:19:17 +02:00
|
|
|
labels_state: '{{ docker_label_state_mode }}'
|
|
|
|
with_items: '{{ docker_node_labels }}'
|
|
|
|
|
|
|
|
when: docker_swarm_node | bool
|
|
|
|
delegate_to: '{{ docker_swarm_manager_main_node_hostname }}'
|
|
|
|
tags: [ 'docker', 'docker_swarm', 'docker_swarm_worker_nodes', 'docker_nodes_labels' ]
|