From 2ea29fee3febc19f06055a7603fe2539890e843d Mon Sep 17 00:00:00 2001 From: chouseknecht Date: Fri, 5 Aug 2016 05:01:55 -0400 Subject: [PATCH] Fix image tag operation. Allows repository in form of repo:tag. If no tag value, defaults to 'latest'. --- .../modules/cloud/docker/docker_image.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py index 6528c28b839..a860df59081 100644 --- a/lib/ansible/modules/cloud/docker/docker_image.py +++ b/lib/ansible/modules/cloud/docker/docker_image.py @@ -91,7 +91,8 @@ options: required: false repository: description: - - Full path to a repository. Use with state C(present) to tag the image into the repository. + - Full path to a repository. Use with state C(present) to tag the image into the repository. Expects + format I(repository:tag). If no tag is provided, will default to 'latest'. required: false version_added: "2.1" state: @@ -425,13 +426,16 @@ class ImageManager(DockerBaseClass): :return: None ''' repo, repo_tag = parse_repository_tag(repository) + if not repo_tag: + repo_tag = "latest" image = self.client.find_image(name=repo, tag=repo_tag) found = 'found' if image else 'not found' self.log("image %s was %s" % (repo, found)) + if not image or force: - self.log("tagging %s:%s to %s" % (name, tag, repository)) + self.log("tagging %s:%s to %s:%s" % (name, tag, repo, repo_tag)) self.results['changed'] = True - self.results['actions'].append("Tagged image %s:%s to %s" % (name, tag, repository)) + self.results['actions'].append("Tagged image %s:%s to %s:%s" % (name, tag, repo, repo_tag)) if not self.check_mode: try: # Finding the image does not always work, especially running a localhost registry. In those @@ -439,14 +443,14 @@ class ImageManager(DockerBaseClass): image_name = name if tag and not re.search(tag, name): image_name = "%s:%s" % (name, tag) - tag_status = self.client.tag(image_name, repository, tag=tag, force=True) + tag_status = self.client.tag(image_name, repo, tag=repo_tag, force=True) if not tag_status: raise Exception("Tag operation failed.") except Exception as exc: - self.fail("Error: failed to tag image %s - %s" % (name, str(exc))) - self.results['image'] = self.client.find_image(name=repository, tag=tag) + self.fail("Error: failed to tag image - %s" % str(exc)) + self.results['image'] = self.client.find_image(name=repo, tag=repo_tag) if push: - self.push_image(repository, tag) + self.push_image(repo, repo_tag) def build_image(self): '''