1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00

podman_image: only set changed=true if there is a new image

with force: true, podman_image would always report changed regardless
of whether or not the pull or build operation resulted in a new image.
With this commit, check the image digest before and after and only
reported changed if the digest is different.
This commit is contained in:
Lars Kellogg-Stedman 2020-03-29 15:32:57 -04:00
parent cb33fd658b
commit 5d7e5c3a5a

View file

@ -424,20 +424,27 @@ class PodmanImageManager(object):
def present(self):
image = self.find_image()
if image:
digest_before = image[0].get('Digest', image[0].get('digest'))
else:
digest_before = None
if not image or self.force:
if self.path:
# Build the image
self.results['actions'].append('Built image {image_name} from {path}'.format(image_name=self.image_name, path=self.path))
self.results['changed'] = True
if not self.module.check_mode:
self.results['image'] = self.build_image()
else:
# Pull the image
self.results['actions'].append('Pulled image {image_name}'.format(image_name=self.image_name))
self.results['changed'] = True
if not self.module.check_mode:
self.results['image'] = self.pull_image()
image = self.find_image()
digest_after = image[0].get('Digest', image[0].get('digest'))
self.results['changed'] = digest_before != digest_after
if self.push:
# Push the image
if '/' in self.image_name: