mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
[docker_image] fix the changed state for tagging and pushing (#53451)
* [docker_image] fix the changed state for tagging and pushing Signed-off-by: Jakob Ackermann <das7pad@outlook.com> * [docker_image] add tests for (force) tagging and force pushing Signed-off-by: Jakob Ackermann <das7pad@outlook.com> * [docker_image] add a news fragment for the fixed force tag/push behavior Signed-off-by: Jakob Ackermann <das7pad@outlook.com>
This commit is contained in:
parent
853f65059a
commit
13ab9a61a8
3 changed files with 53 additions and 0 deletions
|
@ -468,11 +468,15 @@ class ImageManager(DockerBaseClass):
|
|||
if not self.check_mode:
|
||||
status = None
|
||||
try:
|
||||
changed = False
|
||||
for line in self.client.push(repository, tag=tag, stream=True, decode=True):
|
||||
self.log(line, pretty_print=True)
|
||||
if line.get('errorDetail'):
|
||||
raise Exception(line['errorDetail']['message'])
|
||||
status = line.get('status')
|
||||
if status == 'Pushing':
|
||||
changed = True
|
||||
self.results['changed'] = changed
|
||||
except Exception as exc:
|
||||
if re.search('unauthorized', str(exc)):
|
||||
if re.search('authentication required', str(exc)):
|
||||
|
@ -524,6 +528,9 @@ class ImageManager(DockerBaseClass):
|
|||
except Exception as exc:
|
||||
self.fail("Error: failed to tag image - %s" % str(exc))
|
||||
self.results['image'] = self.client.find_image(name=repo, tag=repo_tag)
|
||||
if image and image['Id'] == self.results['image']['Id']:
|
||||
self.results['changed'] = False
|
||||
|
||||
if push:
|
||||
self.push_image(repo, repo_tag)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue