Working setup
This commit is contained in:
@@ -20,64 +20,16 @@
|
||||
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 }}
|
||||
# ansible_eth1={{ ansible_eth1.ipv4.address }}
|
||||
|
||||
# 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: Debug IPs
|
||||
debug:
|
||||
msg: |
|
||||
Current hostname: {{ inventory_hostname }}
|
||||
ansible_eth1 full: {{ ansible_eth1 }}
|
||||
ansible_eth1 ipv4: {{ ansible_eth1.ipv4 }}
|
||||
ansible_eth1 ipv4 address: {{ ansible_eth1.ipv4.address }}
|
||||
advertise_addr: {{ ansible_eth1.ipv4.address }}
|
||||
ansible_eth0: {{ ansible_eth0.ipv4.address }}
|
||||
- name: Gather master facts
|
||||
ansible.builtin.setup:
|
||||
delegate_to: "{{ groups['swarm_master'][0] }}"
|
||||
run_once: true
|
||||
register: master_facts
|
||||
|
||||
# Needed as gathering master facts will overwrite
|
||||
- name: Regather node facts
|
||||
ansible.builtin.setup:
|
||||
|
||||
# - 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 }}
|
||||
# remote_addrs: {{ master_facts.ansible_facts ['ansible_eth1']['ipv4']['address'] }}
|
||||
# advertise_addr: {{ ansible_eth1.ipv4.address }}
|
||||
|
||||
- name: Debug IPs
|
||||
debug:
|
||||
msg: |
|
||||
remote_addrs: {{ master_facts.ansible_facts['ansible_eth1']['ipv4']['address'] }}:2377
|
||||
advertise_addr: {{ ansible_eth1.ipv4.address }}
|
||||
ansible_eth0: {{ ansible_eth0.ipv4.address }}
|
||||
|
||||
- name: Add nodes
|
||||
community.docker.docker_swarm:
|
||||
state: join
|
||||
@@ -85,6 +37,10 @@
|
||||
remote_addrs:
|
||||
- "{{ master_facts.ansible_facts['ansible_eth1']['ipv4']['address'] }}:2377"
|
||||
advertise_addr: "{{ ansible_eth1.ipv4.address }}"
|
||||
# listen_addr: "{{ ansible_eth1.ipv4.address }}" # You already added this
|
||||
# data_path_addr: "{{ ansible_eth1.ipv4.address }}"
|
||||
|
||||
|
||||
- name: Replace node labels with new labels
|
||||
community.docker.docker_node:
|
||||
hostname: "{{ inventory_hostname }}"
|
||||
labels: "{{ dict(group_names | zip(['true'] * group_names | length)) }}"
|
||||
labels_state: replace
|
||||
delegate_to: "{{ groups['swarm_master'][0] }}"
|
||||
|
||||
Reference in New Issue
Block a user