68 lines
2.5 KiB
YAML
68 lines
2.5 KiB
YAML
---
|
|
- hosts: swarm_workers
|
|
become: true
|
|
gather_facts: yes
|
|
|
|
vars:
|
|
roles:
|
|
- role: geerlingguy.swap
|
|
- role: geerlingguy.docker
|
|
- role: common
|
|
|
|
tasks:
|
|
- name: Get worker join token from master
|
|
slurp:
|
|
src: /tmp/swarm_worker_token
|
|
register: worker_token_file
|
|
delegate_to: "{{ groups['swarm_master'][0] }}"
|
|
|
|
- name: Decode worker join token
|
|
set_fact:
|
|
worker_token: "{{ worker_token_file.content | b64decode | trim }}"
|
|
|
|
- name: Debug all relevant variables
|
|
debug:
|
|
msg: |
|
|
=== SWARM JOIN DEBUG INFO ===
|
|
Current host: {{ inventory_hostname }}
|
|
Current host IP: {{ ansible_host }}
|
|
|
|
Master group hosts: {{ groups['swarm_master'] }}
|
|
First master: {{ groups['swarm_master'][0] }}
|
|
|
|
Master hostvars:
|
|
- ansible_host: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] }}
|
|
- inventory_hostname: {{ hostvars[groups['swarm_master'][0]]['inventory_hostname'] }}
|
|
|
|
Remote address calculation:
|
|
- Raw master ansible_host: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] }}
|
|
- Fallback to hostname: {{ groups['swarm_master'][0] }}
|
|
- Final address: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] | default(groups['swarm_master'][0]) }}
|
|
- With port: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] | default(groups['swarm_master'][0]) }}:2377
|
|
|
|
Join token (first 10 chars): {{ worker_token[:10] }}...
|
|
|
|
- name: Gather master facts
|
|
ansible.builtin.setup:
|
|
delegate_to: "{{ groups['swarm_master'][0] }}"
|
|
run_once: true
|
|
register: master_facts
|
|
|
|
- name: Debug master hostvars
|
|
debug:
|
|
msg: |
|
|
Master hostvars keys: {{ hostvars[groups['swarm_master'][0]].keys() | list }}
|
|
Master ansible_eth1: {{ hostvars[groups['swarm_master'][0]].ansible_eth1 | default('Not available') }}
|
|
Master node: {{ groups['swarm_master'][0] }}
|
|
Master ansible_default_ipv4: {{ hostvars[groups['swarm_master'][0]] }}
|
|
Master ansible_default_ipv4: {{ master_facts.ansible_facts }}
|
|
FINAL IP: {{ master_facts.ansible_facts ['ansible_eth1']['ipv4']['address'] }}
|
|
|
|
- name: Add nodes
|
|
community.docker.docker_swarm:
|
|
state: join
|
|
join_token: "{{ worker_token }}"
|
|
remote_addrs:
|
|
- "{{ master_facts.ansible_facts ['ansible_eth1']['ipv4']['address'] }}:2377"
|
|
advertise_addr: "{{ ansible_eth1.ipv4.address }}"
|
|
|