From bd20622a16d63d1b92a304b8236007a15fdc3f75 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Thu, 17 Sep 2026 08:59:23 +0000 Subject: [PATCH] download: define utility variables (#13521) local_release_dir has insufficient nuances, as it needs to handle several cases, - where to put downloaded artifacts - where to search for when installing artifacts - where to search for when using artifacts (passing them via lookup to kubectl stdin for instance) Furthermore, depending on how the user set up download delegation, the value we want can be on the host the tasks is executing, on the delegated hosts, etc. Define variables on top of local_release_dir for differents contexts, handling which host context to use depending on `download_delegate`. Mostly, this boils down to choosing the correct `host` for hostvars[host]['local_release_dir']. --- .../defaults/main/download.yml | 1 - .../kubespray_defaults/defaults/main/main.yml | 2 +- .../kubespray_defaults/vars/main/download.yml | 23 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 roles/kubespray_defaults/vars/main/download.yml diff --git a/roles/kubespray_defaults/defaults/main/download.yml b/roles/kubespray_defaults/defaults/main/download.yml index 8284db1ba..91c12c5fb 100644 --- a/roles/kubespray_defaults/defaults/main/download.yml +++ b/roles/kubespray_defaults/defaults/main/download.yml @@ -1,5 +1,4 @@ --- -local_release_dir: /tmp/releases download_cache_dir: /tmp/kubespray_cache # If this is true, debug information will be displayed but diff --git a/roles/kubespray_defaults/defaults/main/main.yml b/roles/kubespray_defaults/defaults/main/main.yml index eb9171119..7217d96ab 100644 --- a/roles/kubespray_defaults/defaults/main/main.yml +++ b/roles/kubespray_defaults/defaults/main/main.yml @@ -114,7 +114,7 @@ containerd_bin_dir: "{{ bin_dir }}" etcd_data_dir: /var/lib/etcd # Where the binaries will be downloaded. # Note: ensure that you've enough disk space (about 1G) -local_release_dir: "/tmp/releases" +local_release_dir: "{{ default_local_release_dir }}" # Random shifts for retrying failed ops like pushing/downloading retry_stagger: 5 diff --git a/roles/kubespray_defaults/vars/main/download.yml b/roles/kubespray_defaults/vars/main/download.yml new file mode 100644 index 000000000..1484d39a5 --- /dev/null +++ b/roles/kubespray_defaults/vars/main/download.yml @@ -0,0 +1,23 @@ +--- +## Variables used by roles/download and task installing artefacts on node + +# Where ansible should look for artefacts when installing binaries / pre-loading container image +# This is subtly different from local_release_dir, because it takes into +# account `download_delegate`, and in particular the scenario where: +# - hostvars['some_host']['download_delegate'] == 'other_host' or 'localhost' -> both scenario will result in the artefact transiting by localhost +# - hostvars['localhost']['local_release_dir'] != hostvars['some_host']['local_release_dir'] +# We explicitly check hostvars +install_source_dir: "{{ + hostvars[ + inventory_hostname if download_delegate == inventory_hostname + else 'localhost' + ]['local_release_dir'] | default(default_local_release_dir) +}}" + +# This always refers to the value of `local_release_dir` for localhost +# used by tasks which need to refer to paths on the controller, for instance, using lookup('file') +install_source_localhost: "{{ hostvars['localhost']['local_release_dir'] | default(default_local_release_dir) }}" + +# This variable is the default for local_release_dir and is used to refer to +# the default even when `local_release_dir` is overridden by inventory +default_local_release_dir: /tmp/releases