--- - name: Determine node platform (best-effort) ansible.builtin.set_fact: _k3s_node_platform: >- linux/{{ { 'x86_64': 'amd64', 'amd64': 'amd64', 'aarch64': 'arm64', 'arm64': 'arm64', }.get((ansible_architecture | default('x86_64')), (ansible_architecture | default('x86_64'))) }} changed_when: false - name: Infer tarball platform from filename (best-effort) ansible.builtin.set_fact: _k3s_tar_platform_hint: >- {{ 'linux/amd64' if (k3s_import_image.path | basename) is search('linux-amd64') else ( 'linux/arm64' if (k3s_import_image.path | basename) is search('linux-arm64') else '' ) }} changed_when: false - name: Fail fast on obvious platform mismatch to avoid heavy import I/O ansible.builtin.fail: msg: >- Refusing to import {{ k3s_import_image.path | basename }} on {{ inventory_hostname }}: tarball appears to target {{ _k3s_tar_platform_hint }}, but node platform is {{ _k3s_node_platform }}. Use a matching tarball (or build/export a multi-arch tar) for this node. when: - _k3s_tar_platform_hint | default('') != '' - _k3s_node_platform | default('') != '' - _k3s_tar_platform_hint != _k3s_node_platform - name: "Check if image {{ k3s_import_image.image }} already exists" ansible.builtin.shell: "k3s ctr -n k8s.io images list -q | grep -qx -e '{{ k3s_import_image.image }}' -e 'docker.io/{{ k3s_import_image.image }}'" register: _k3s_image_check changed_when: false failed_when: false when: k3s_import_image.image | default('') != '' - name: "Copy image tarball {{ k3s_import_image.path | basename }} to k3s node" block: - name: "Copy image tarball {{ k3s_import_image.path | basename }} to k3s node" ansible.builtin.copy: src: "{{ k3s_import_image.path }}" dest: "/tmp/{{ k3s_import_image.path | basename }}" mode: "0644" - name: "Import image {{ k3s_import_image.path | basename }} into k3s containerd" ansible.builtin.command: k3s ctr -n k8s.io images import --no-unpack "/tmp/{{ k3s_import_image.path | basename }}" register: _k3s_ctr_import changed_when: _k3s_ctr_import.rc == 0 failed_when: false - name: Fail with actionable diagnostics when import failed ansible.builtin.fail: msg: >- Failed to import {{ k3s_import_image.path | basename }} into k3s containerd on {{ inventory_hostname }} (rc={{ _k3s_ctr_import.rc }}). stderr={{ _k3s_ctr_import.stderr | default('') | trim }} stdout={{ _k3s_ctr_import.stdout | default('') | trim }} Hint: if you see "image might be filtered out", the tarball usually does not contain a manifest matching this node platform ({{ _k3s_node_platform }}). when: _k3s_ctr_import.rc != 0 always: - name: "Remove temporary tarball for {{ k3s_import_image.path | basename }}" ansible.builtin.file: path: "/tmp/{{ k3s_import_image.path | basename }}" state: absent when: k3s_import_image.image | default('') == '' or _k3s_image_check.rc != 0