From e217ba6e19835d843895a9be91ad6c5039349bba Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Tue, 30 Oct 2018 01:48:30 -0700 Subject: [PATCH] docker_image: Fix up 'changed' event in force mode (#33754) * docker_image: Fix up 'changed' event in force mode This is the same as https://github.com/ansible/ansible/pull/19235 except it applies to all image-building modes (building the image locally, loading the image from an archive, or pulling the image), rather than only when pulling the image. * Use 'dummy' rather than '_' as unused variable name. * Add changelog fragment for pull request #33754 --- .../33754-docker_image_fix_changed_in_force_mode.yaml | 2 ++ lib/ansible/modules/cloud/docker/docker_image.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/33754-docker_image_fix_changed_in_force_mode.yaml diff --git a/changelogs/fragments/33754-docker_image_fix_changed_in_force_mode.yaml b/changelogs/fragments/33754-docker_image_fix_changed_in_force_mode.yaml new file mode 100644 index 0000000000..8df8fd602f --- /dev/null +++ b/changelogs/fragments/33754-docker_image_fix_changed_in_force_mode.yaml @@ -0,0 +1,2 @@ +minor_changes: +- "docker_image - set ``changed`` to ``false`` when using ``force: yes`` to load or build an image that ends up being identical to one already present on the Docker host." diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py index b6ef08c4c3..b876c031ad 100644 --- a/lib/ansible/modules/cloud/docker/docker_image.py +++ b/lib/ansible/modules/cloud/docker/docker_image.py @@ -348,9 +348,9 @@ class ImageManager(DockerBaseClass): self.results['actions'].append('Pulled image %s:%s' % (self.name, self.tag)) self.results['changed'] = True if not self.check_mode: - self.results['image'], already_latest = self.client.pull_image(self.name, tag=self.tag) - if already_latest: - self.results['changed'] = False + self.results['image'], dummy = self.client.pull_image(self.name, tag=self.tag) + if not self.check_mode and image and image['Id'] == self.results['image']['Id']: + self.results['changed'] = False if self.archive_path: self.archive_image(self.name, self.tag)