--- - name: Check for runner-provided Rancher image archives stat: path: "{{ playbook_dir }}/../outputs/bootstrap-image-archives/{{ item | regex_replace('[/:]', '_') }}.tar" delegate_to: localhost become: false register: rancher_image_archive_stats loop: "{{ rancher_images_to_prepull }}" - name: Ensure remote Rancher image archive directory exists file: path: /tmp/bootstrap-image-archives state: directory mode: "0755" - name: Copy runner-provided Rancher image archives copy: src: "{{ item.stat.path }}" dest: "/tmp/bootstrap-image-archives/{{ item.item | regex_replace('[/:]', '_') }}.tar" mode: "0644" loop: "{{ rancher_image_archive_stats.results }}" loop_control: label: "{{ item.item }}" when: item.stat.exists - name: Import or pull Rancher images into containerd shell: | if /usr/local/bin/ctr -n k8s.io images ls -q | grep -Fx -- "{{ item }}" >/dev/null; then echo "already present" exit 0 fi archive="/tmp/bootstrap-image-archives/{{ item | regex_replace('[/:]', '_') }}.tar" if [ -s "${archive}" ]; then for attempt in 1 2 3; do if /usr/local/bin/ctr -n k8s.io images import "${archive}" && /usr/local/bin/ctr -n k8s.io images ls -q | grep -Fx -- "{{ item }}" >/dev/null; then echo "imported image" exit 0 fi sleep 10 done fi for attempt in 1 2 3 4 5; do if timeout 180s /usr/local/bin/ctr -n k8s.io images pull "{{ item }}"; then echo "pulled image" exit 0 fi sleep 10 done exit 1 args: executable: /bin/bash register: rancher_image_pull loop: "{{ rancher_images_to_prepull }}" changed_when: "'imported image' in rancher_image_pull.stdout or 'pulled image' in rancher_image_pull.stdout"