Fix port issue as buildin. Setup reassigns the default vars

This commit is contained in:
lif
2025-10-13 09:04:32 +01:00
parent 0c46b66b7b
commit 5b3cd2b8b6
3 changed files with 30 additions and 2 deletions

View File

@@ -28,11 +28,18 @@
- 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
- name: Debug master hostvars
debug:
msg: |
advertise_addr: {{ ansible_eth1.ipv4.address }}
ansible_eth0: {{ ansible_eth0.ipv4.address }}
- name: Init a new swarm with default parameters
community.docker.docker_swarm:
state: present
advertise_addr: "{{ ansible_eth1.ipv4.address }}"
listen_addr: "{{ ansible_eth1.ipv4.address }}"
# listen_addr: "{{ ansible_eth1.ipv4.address }}"
# data_path_addr: "{{ ansible_eth1.ipv4.address }}"
- name: print listen addr
debug:

View File

@@ -43,11 +43,22 @@
# 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
- name: Regather node facts
ansible.builtin.setup:
# - name: Debug master hostvars
# debug:
@@ -59,6 +70,13 @@
# 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:
@@ -67,5 +85,6 @@
remote_addrs:
- "{{ master_facts.ansible_facts['ansible_eth1']['ipv4']['address'] }}:2377"
advertise_addr: "{{ ansible_eth1.ipv4.address }}"
listen_addr: "{{ ansible_eth1.ipv4.address }}:2377"
# listen_addr: "{{ ansible_eth1.ipv4.address }}" # You already added this
# data_path_addr: "{{ ansible_eth1.ipv4.address }}"

View File

@@ -121,6 +121,8 @@ services:
- "traefik.http.routers.whoami.middlewares=whoami-stripprefix"
# Expose the whoami port number to Traefik
- "traefik.http.services.whoami.loadbalancer.server.port=80"
mode: replicated
replicas: 1
# Define the overlay network for Swarm
networks: