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).
This commit is contained in:
Arnaud RENARD 2019-06-13 16:23:41 +02:00 committed by Alicia Cozine
parent 6131de29d4
commit 1a5fd720a4
3 changed files with 12 additions and 7 deletions

View file

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

View file

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

View file

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