From 2d194af85e1a7cf63042f08783cc619fade77e2d Mon Sep 17 00:00:00 2001 From: Lihai Tu <92532497+tu1h@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:17:48 +0800 Subject: [PATCH] Limit nodes in gather ansible_default_ipv4 (#11370) Signed-off-by: tu1h --- roles/kubespray-defaults/tasks/fallback_ips.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/roles/kubespray-defaults/tasks/fallback_ips.yml b/roles/kubespray-defaults/tasks/fallback_ips.yml index 26b944746..a1aff37ee 100644 --- a/roles/kubespray-defaults/tasks/fallback_ips.yml +++ b/roles/kubespray-defaults/tasks/fallback_ips.yml @@ -3,14 +3,14 @@ # ansible_default_ipv4 isn't what you think. # Thanks https://medium.com/opsops/ansible-default-ipv4-is-not-what-you-think-edb8ab154b10 -- name: Gather ansible_default_ipv4 from all hosts +- name: Gather ansible_default_ipv4 from all hosts or specific hosts setup: gather_subset: '!all,network' filter: "ansible_default_ipv4" delegate_to: "{{ item }}" delegate_facts: yes when: hostvars[item].ansible_default_ipv4 is not defined - loop: "{{ (groups['k8s_cluster'] | default([]) + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique }}" + loop: "{{ (ansible_play_hosts_all + [groups['kube_control_plane'][0]]) | unique if ansible_limit is defined else (groups['k8s_cluster'] | default([]) + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique }}" run_once: yes ignore_unreachable: true tags: always @@ -19,7 +19,8 @@ set_fact: fallback_ips_base: | --- - {% for item in (groups['k8s_cluster'] | default([]) + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique %} + {% set search_hosts = (ansible_play_hosts_all + [groups['kube_control_plane'][0]]) | unique if ansible_limit is defined else (groups['k8s_cluster'] | default([]) + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique %} + {% for item in search_hosts %} {% set found = hostvars[item].get('ansible_default_ipv4') %} {{ item }}: "{{ found.get('address', '127.0.0.1') }}" {% endfor %}