From b51dc5c8149dc659200b04c14087182344b001f1 Mon Sep 17 00:00:00 2001 From: MasterWaldo Date: Sun, 24 Apr 2022 15:38:53 -0400 Subject: [PATCH] Loop over image names when multiple images present in archive (#413) Signed-off-by: Cory Prelerson --- plugins/modules/podman_load.py | 2 +- .../targets/podman_load/tasks/main.yml | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/modules/podman_load.py b/plugins/modules/podman_load.py index 90f0624..93fbfe9 100644 --- a/plugins/modules/podman_load.py +++ b/plugins/modules/podman_load.py @@ -155,7 +155,7 @@ def load(module, executable): if rc != 0: module.fail_json(msg="Image loading failed: %s" % (err)) image_name_line = [i for i in out.splitlines() if 'Loaded image' in i][0] - image_name = image_name_line.split(":", maxsplit=1)[1].strip() + image_name = image_name_line.split("Loaded image(s): ")[1].split(',')[0].strip() rc, out2, err2 = module.run_command([executable, 'image', 'inspect', image_name]) if rc != 0: module.fail_json(msg="Image %s inspection failed: %s" % (image_name, err2)) diff --git a/tests/integration/targets/podman_load/tasks/main.yml b/tests/integration/targets/podman_load/tasks/main.yml index f7cae8d..3a6258b 100644 --- a/tests/integration/targets/podman_load/tasks/main.yml +++ b/tests/integration/targets/podman_load/tasks/main.yml @@ -52,3 +52,31 @@ that: - image.image != {} - image.image.NamesHistory.0 == "k8s.gcr.io/pause:latest" + +- name: Pull images + containers.podman.podman_image: + name: '{{ item }}' + loop: + - k8s.gcr.io/coredns:1.7.0 + - k8s.gcr.io/echoserver:1.10 + +- name: Clean up multifile + ansible.builtin.file: + path: /tmp/multi.tar + state: absent + +- name: Create multi image file + shell: >- + podman save k8s.gcr.io/coredns:1.7.0 k8s.gcr.io/echoserver:1.10 -o /tmp/multi.tar + +- name: Load image from oci-dir multi image archive + containers.podman.podman_load: + input: /tmp/multi.tar + register: image + +- name: Check it's loaded + assert: + that: + - image.image != {} + - '"k8s.gcr.io/coredns:1.7.0" in image.image.NamesHistory' + - '"k8s.gcr.io/echoserver:1.10" in image.image.NamesHistory'