From 622f82a8d9cd030b4b04fe9da2d53c8c6dc26670 Mon Sep 17 00:00:00 2001 From: Sergey <6213510+sshnaidm@users.noreply.github.com> Date: Tue, 3 Sep 2024 10:30:17 +0300 Subject: [PATCH] Fix logic in Podman images (#832) Fix #831 Signed-off-by: Sagi Shnaidman --- plugins/modules/podman_image.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/modules/podman_image.py b/plugins/modules/podman_image.py index f8c13ac2..e8094ae1 100644 --- a/plugins/modules/podman_image.py +++ b/plugins/modules/podman_image.py @@ -561,6 +561,12 @@ def make_quadlet(self): def find_image(self, image_name=None): if image_name is None: image_name = self.image_name + # Let's find out if image exists + rc, out, err = self._run(['image', 'exists', image_name], ignore_errors=True) + if rc == 0: + inspect_json = self.inspect_image(image_name) + else: + return None args = ['image', 'ls', image_name, '--format', 'json'] rc, images, err = self._run(args, ignore_errors=True) try: @@ -568,14 +574,8 @@ def find_image(self, image_name=None): except json.decoder.JSONDecodeError: self.module.fail_json(msg='Failed to parse JSON output from podman image ls: {out}'.format(out=images)) if len(images) == 0: - # Let's find out if image exists - rc, out, err = self._run(['image', 'exists', image_name], ignore_errors=True) - if rc == 0: - inspect_json = self.inspect_image(image_name) - else: - return None - if len(images) > 0: - inspect_json = self.inspect_image(image_name) + return None + inspect_json = self.inspect_image(image_name) if self._is_target_arch(inspect_json, self.arch) or not self.arch: return images or inspect_json return None