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).
pull/57802/head
Arnaud RENARD 6 years ago committed by Alicia Cozine
parent 6131de29d4
commit 1a5fd720a4

@ -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

@ -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']

@ -256,10 +256,7 @@ 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")
else:
if tmp_file.endswith('.gz'):
role_tar_file = tarfile.open(tmp_file, "r:gz")
raise AnsibleError("the downloaded file does not appear to be a valid tar archive.")
else:
role_tar_file = tarfile.open(tmp_file, "r")
# verify the role's meta file

Loading…
Cancel
Save