diff --git a/plugins/modules/podman_image.py b/plugins/modules/podman_image.py index d66ff5d..6649d6b 100644 --- a/plugins/modules/podman_image.py +++ b/plugins/modules/podman_image.py @@ -512,6 +512,8 @@ class PodmanImageManager(object): if not self.module.check_mode: self.results['image'], output = self.push_image() self.results['stdout'] += "\n" + output + if image and not self.results.get('image'): + self.results['image'] = image def absent(self): image = self.find_image() @@ -537,11 +539,17 @@ class PodmanImageManager(object): args = ['image', 'ls', image_name, '--format', 'json'] rc, images, err = self._run(args, ignore_errors=True) images = json.loads(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) - if self._is_target_arch(inspect_json, self.arch) or not self.arch: - return images - + if self._is_target_arch(inspect_json, self.arch) or not self.arch: + return images or inspect_json return None def _is_target_arch(self, inspect_json=None, arch=None): diff --git a/tests/integration/targets/podman_image/tasks/main.yml b/tests/integration/targets/podman_image/tasks/main.yml index 645d0a0..0db4c05 100644 --- a/tests/integration/targets/podman_image/tasks/main.yml +++ b/tests/integration/targets/podman_image/tasks/main.yml @@ -1,5 +1,18 @@ - name: Test podman_image block: + - name: List all images on host before test + containers.podman.podman_image_info: + + - name: Remove images for test + containers.podman.podman_image: + name: "{{ item }}" + state: absent + loop: + - quay.io/coreos/alpine-sh + - docker.io/alpine + - docker.io/library/ubuntu + - docker.io/library/alpine + - name: Pull image containers.podman.podman_image: executable: "{{ test_executable | default('podman') }}" @@ -47,7 +60,7 @@ - pull1.podman_actions is defined - pull2 is not changed - pull3 is changed - - pull4 is changed + - pull4 is not changed - pull5 is not changed - pull6 is changed - "'alpine-sh' in images.stdout" @@ -83,14 +96,14 @@ state: absent register: rmi3 - - name: Try to remove docker.io image using short url + - name: Remove docker.io image using short url containers.podman.podman_image: executable: "{{ test_executable | default('podman') }}" name: docker.io/alpine state: absent register: rmi4 - - name: Remove docker.io image using normalised url + - name: Try to remove docker.io image using normalised url containers.podman.podman_image: executable: "{{ test_executable | default('podman') }}" name: docker.io/library/alpine @@ -121,8 +134,8 @@ - rmi1 is changed - rmi2 is not changed - rmi3 is changed - - rmi4 is not changed - - rmi5 is changed + - rmi4 is changed + - rmi5 is not changed - rmi6 is changed - "'alpine-sh' not in images.stdout" - "'library/ubuntu' not in images.stdout"