From 1a5fd720a45d64d916d31c52c54020c4de6dfe68 Mon Sep 17 00:00:00 2001 From: Arnaud RENARD Date: Thu, 13 Jun 2019 16:23:41 +0200 Subject: [PATCH] Ansible galaxy role download should not have to perform aditionnal check against tar archive file extension #56616. (#56617) Ansible galaxy role download checked for `.tar.gz`, but `tarfile.is_tarfile(...)` can identify and open any valid tarfile. This change uses transparent stream compression to make `.tar.gz` and `.tar.bz2` formats valid with python 2.6.x/2.7.x (as well as `.tar.xz` with python 3.x). --- docs/docsite/rst/reference_appendices/galaxy.rst | 10 +++++++++- lib/ansible/cli/galaxy.py | 2 +- lib/ansible/galaxy/role.py | 7 ++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/docsite/rst/reference_appendices/galaxy.rst b/docs/docsite/rst/reference_appendices/galaxy.rst index 052e1974e47..352d79cb49c 100644 --- a/docs/docsite/rst/reference_appendices/galaxy.rst +++ b/docs/docsite/rst/reference_appendices/galaxy.rst @@ -120,7 +120,15 @@ Use the following example as a guide for specifying roles in *requirements.yml*: # from a webserver, where the role is packaged in a tar.gz - src: https://some.webserver.example.com/files/master.tar.gz - name: http-role + name: http-role-gz + + # from a webserver, where the role is packaged in a tar.bz2 + - src: https://some.webserver.example.com/files/master.tar.bz2 + name: http-role-bz2 + + # from a webserver, where the role is packaged in a tar.xz (Python 3.x only) + - src: https://some.webserver.example.com/files/master.tar.xz + name: http-role-xz # from Bitbucket - src: git+https://bitbucket.org/willthames/git-ansible-galaxy diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 25304abad7e..cf214c2e969 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -319,7 +319,7 @@ class GalaxyCLI(CLI): def execute_install(self): """ uses the args list of roles to be installed, unless -f was specified. The list of roles - can be a name (which will be downloaded via the galaxy API and github), or it can be a local .tar.gz file. + can be a name (which will be downloaded via the galaxy API and github), or it can be a local tar archive file. """ role_file = context.CLIARGS['role_file'] diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py index 61776c88509..a7ecdc08ce4 100644 --- a/lib/ansible/galaxy/role.py +++ b/lib/ansible/galaxy/role.py @@ -256,12 +256,9 @@ class GalaxyRole(object): display.debug("installing from %s" % tmp_file) if not tarfile.is_tarfile(tmp_file): - raise AnsibleError("the file downloaded was not a tar.gz") + raise AnsibleError("the downloaded file does not appear to be a valid tar archive.") else: - if tmp_file.endswith('.gz'): - role_tar_file = tarfile.open(tmp_file, "r:gz") - else: - role_tar_file = tarfile.open(tmp_file, "r") + role_tar_file = tarfile.open(tmp_file, "r") # verify the role's meta file meta_file = None members = role_tar_file.getmembers()