Skip to content

Commit b91ddd3

Browse files
authored
Fix pulling short image name (#614)
Also return image data when pulling it. Signed-off-by: Sagi Shnaidman <[email protected]>
1 parent 7a30745 commit b91ddd3

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

plugins/modules/podman_image.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ def present(self):
512512
if not self.module.check_mode:
513513
self.results['image'], output = self.push_image()
514514
self.results['stdout'] += "\n" + output
515+
if image and not self.results.get('image'):
516+
self.results['image'] = image
515517

516518
def absent(self):
517519
image = self.find_image()
@@ -537,11 +539,17 @@ def find_image(self, image_name=None):
537539
args = ['image', 'ls', image_name, '--format', 'json']
538540
rc, images, err = self._run(args, ignore_errors=True)
539541
images = json.loads(images)
542+
if len(images) == 0:
543+
# Let's find out if image exists
544+
rc, out, err = self._run(['image', 'exists', image_name], ignore_errors=True)
545+
if rc == 0:
546+
inspect_json = self.inspect_image(image_name)
547+
else:
548+
return None
540549
if len(images) > 0:
541550
inspect_json = self.inspect_image(image_name)
542-
if self._is_target_arch(inspect_json, self.arch) or not self.arch:
543-
return images
544-
551+
if self._is_target_arch(inspect_json, self.arch) or not self.arch:
552+
return images or inspect_json
545553
return None
546554

547555
def _is_target_arch(self, inspect_json=None, arch=None):

tests/integration/targets/podman_image/tasks/main.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
- name: Test podman_image
22
block:
3+
- name: List all images on host before test
4+
containers.podman.podman_image_info:
5+
6+
- name: Remove images for test
7+
containers.podman.podman_image:
8+
name: "{{ item }}"
9+
state: absent
10+
loop:
11+
- quay.io/coreos/alpine-sh
12+
- docker.io/alpine
13+
- docker.io/library/ubuntu
14+
- docker.io/library/alpine
15+
316
- name: Pull image
417
containers.podman.podman_image:
518
executable: "{{ test_executable | default('podman') }}"
@@ -47,7 +60,7 @@
4760
- pull1.podman_actions is defined
4861
- pull2 is not changed
4962
- pull3 is changed
50-
- pull4 is changed
63+
- pull4 is not changed
5164
- pull5 is not changed
5265
- pull6 is changed
5366
- "'alpine-sh' in images.stdout"
@@ -83,14 +96,14 @@
8396
state: absent
8497
register: rmi3
8598

86-
- name: Try to remove docker.io image using short url
99+
- name: Remove docker.io image using short url
87100
containers.podman.podman_image:
88101
executable: "{{ test_executable | default('podman') }}"
89102
name: docker.io/alpine
90103
state: absent
91104
register: rmi4
92105

93-
- name: Remove docker.io image using normalised url
106+
- name: Try to remove docker.io image using normalised url
94107
containers.podman.podman_image:
95108
executable: "{{ test_executable | default('podman') }}"
96109
name: docker.io/library/alpine
@@ -121,8 +134,8 @@
121134
- rmi1 is changed
122135
- rmi2 is not changed
123136
- rmi3 is changed
124-
- rmi4 is not changed
125-
- rmi5 is changed
137+
- rmi4 is changed
138+
- rmi5 is not changed
126139
- rmi6 is changed
127140
- "'alpine-sh' not in images.stdout"
128141
- "'library/ubuntu' not in images.stdout"

0 commit comments

Comments
 (0)