Add docker-swarm-cluster/roles/swarm/tasks/main.yml
This commit is contained in:
parent
1bc94d2b16
commit
ecb70e22c2
1 changed files with 24 additions and 0 deletions
24
docker-swarm-cluster/roles/swarm/tasks/main.yml
Normal file
24
docker-swarm-cluster/roles/swarm/tasks/main.yml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
- block:
|
||||
- name: Initialize the Docker Swarm on Manager node
|
||||
become: yes
|
||||
command: >
|
||||
docker swarm init
|
||||
--advertise-addr {{ manager_ip }}
|
||||
register: result
|
||||
when: inventory_hostname == 'manager1'
|
||||
|
||||
- set_fact:
|
||||
join_command: "{{ result.stdout_lines[-1].split(':')[1].strip() }}"
|
||||
when: inventory_hostname == 'manager1' and result is success
|
||||
|
||||
- debug:
|
||||
msg: "Swarm initialized successfully with token: {{ join_command }}"
|
||||
when: inventory_hostname == 'manager1' and result is success
|
||||
|
||||
- block:
|
||||
- name: Join Worker nodes to Swarm cluster
|
||||
become: yes
|
||||
shell: |
|
||||
echo "{{ join_command }}" | docker swarm join --token {{ swarm_token_worker }} {{ manager_ip }}:2377
|
||||
when: inventory_hostname != 'manager1'
|
||||
Loading…
Reference in a new issue