From 9761250a4b179d2064a49e2f4b4a66ba423de26f Mon Sep 17 00:00:00 2001 From: Mick Bass Date: Sun, 27 Sep 2015 17:12:13 -0600 Subject: [PATCH 1/2] Allow tree-ish to be used for galaxy role version Ensure that ansible-galaxy version can be a branch, a tag, or any tree-ish supported by git including specific commit IDs. For git scm roles, adds an explicit git checkout of the specified role_version prior to the git archive. This means that we'll always archive from HEAD of whatever role_version is checked out. role_version can be a branch, a tag, or any supported by git including specific commit IDs. These changes also ensure ansible-galaxy works for scm clones when specified version differs from repository default branch. --- lib/ansible/galaxy/role.py | 2 -- lib/ansible/playbook/role/requirement.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py index dc9da5d79ce..5acd26c92dc 100644 --- a/lib/ansible/galaxy/role.py +++ b/lib/ansible/galaxy/role.py @@ -310,5 +310,3 @@ class GalaxyRole(object): } """ return dict(scm=self.scm, src=self.src, version=self.version, name=self.name) - - diff --git a/lib/ansible/playbook/role/requirement.py b/lib/ansible/playbook/role/requirement.py index 1a640247e25..807dd1e82fd 100644 --- a/lib/ansible/playbook/role/requirement.py +++ b/lib/ansible/playbook/role/requirement.py @@ -190,6 +190,17 @@ class RoleRequirement(RoleDefinition): if rc != 0: raise AnsibleError ("- command %s failed in directory %s (rc=%s)" % (' '.join(clone_cmd), tempdir, rc)) + if scm == 'git' and version: + checkout_cmd = [scm, 'checkout', version] + with open('/dev/null', 'w') as devnull: + try: + popen = subprocess.Popen(checkout_cmd, cwd=os.path.join(tempdir, name), stdout=devnull, stderr=devnull) + except (IOError, OSError): + raise AnsibleError("error executing: %s" % " ".join(checkout_cmd)) + rc = popen.wait() + if rc != 0: + raise AnsibleError("- command %s failed in directory %s (rc=%s)" % (' '.join(checkout_cmd), tempdir, rc)) + temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.tar') if scm == 'hg': archive_cmd = ['hg', 'archive', '--prefix', "%s/" % name] From ff19233ad33dc989e997e69b4f36cab56fae74da Mon Sep 17 00:00:00 2001 From: Will Thames Date: Thu, 22 Oct 2015 14:18:48 +1000 Subject: [PATCH 2/2] Add tests for #10620 --- test/integration/galaxy_roles.yml | 2 +- test/integration/galaxy_rolesfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/galaxy_roles.yml b/test/integration/galaxy_roles.yml index 5f4373c5004..3d2121f1683 100644 --- a/test/integration/galaxy_roles.yml +++ b/test/integration/galaxy_roles.yml @@ -3,7 +3,7 @@ name: oracle_java7 - src: git+http://bitbucket.org/willthames/git-ansible-galaxy - version: v1.6 + version: pr-10620 - src: http://bitbucket.org/willthames/hg-ansible-galaxy scm: hg diff --git a/test/integration/galaxy_rolesfile b/test/integration/galaxy_rolesfile index b78cdc11481..047eef95502 100644 --- a/test/integration/galaxy_rolesfile +++ b/test/integration/galaxy_rolesfile @@ -1,7 +1,7 @@ # deliberate non-empty whitespace line to follow -git+https://bitbucket.org/willthames/git-ansible-galaxy,v1.6 +git+https://bitbucket.org/willthames/git-ansible-galaxy,pr-10620 hg+https://bitbucket.org/willthames/hg-ansible-galaxy https://bitbucket.org/willthames/http-ansible-galaxy/get/master.tar.gz,,http-role # comment