24 lines
No EOL
801 B
YAML
24 lines
No EOL
801 B
YAML
---
|
|
- 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' |