1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-03-22 02:29:08 +00:00

Catch exceptions when no JSON output in podman_image (#680)

Fix #676
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
Sergey 2023-11-30 15:12:38 +02:00 committed by GitHub
parent 2d006399b0
commit c3b38b54a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -542,7 +542,10 @@ class PodmanImageManager(object):
image_name = self.image_name
args = ['image', 'ls', image_name, '--format', 'json']
rc, images, err = self._run(args, ignore_errors=True)
images = json.loads(images)
try:
images = json.loads(images)
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)
@ -577,7 +580,10 @@ class PodmanImageManager(object):
image_name = self.image_name
args = ['inspect', image_name, '--format', 'json']
rc, image_data, err = self._run(args)
image_data = json.loads(image_data)
try:
image_data = json.loads(image_data)
except json.decoder.JSONDecodeError:
self.module.fail_json(msg='Failed to parse JSON output from podman inspect: {out}'.format(out=image_data))
if len(image_data) > 0:
return image_data
else: