From cd26cc8a0d2d75e8c625ad3956847a5767c24466 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 2 May 2016 11:27:44 -0700 Subject: [PATCH] Detection of handler depends on the wrong handler failing to list the contents of the tarfile. (#3584) Use explicit compression types with the python tarfile library to achieve that. --- lib/ansible/modules/files/unarchive.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/files/unarchive.py b/lib/ansible/modules/files/unarchive.py index 6ded1e779ba..1727c9cbd62 100644 --- a/lib/ansible/modules/files/unarchive.py +++ b/lib/ansible/modules/files/unarchive.py @@ -493,6 +493,7 @@ class TgzArchive(object): # Fallback to tar self.cmd_path = self.module.get_bin_path('tar') self.zipflag = 'z' + self.compress_mode = 'gz' self._files_in_archive = [] def _get_tar_fileobj(self): @@ -507,7 +508,7 @@ class TgzArchive(object): # The use of Python's tarfile module here allows us to easily avoid tricky file encoding # problems. Ref #11348 try: - tf = tarfile.open(fileobj=self._get_tar_fileobj()) + tf = tarfile.open(fileobj=self._get_tar_fileobj(), mode='r:%s' % self.compress_mode) except Exception: raise UnarchiveError('Unable to list files in the archive') @@ -593,7 +594,10 @@ class TgzArchive(object): class TarArchive(TgzArchive): def __init__(self, src, dest, file_args, module): super(TarArchive, self).__init__(src, dest, file_args, module) + # argument to tar self.zipflag = '' + # parameter for python tarfile library + self.compress_mode = '' # class to handle bzip2 compressed tar files @@ -601,6 +605,7 @@ class TarBzipArchive(TgzArchive): def __init__(self, src, dest, file_args, module): super(TarBzipArchive, self).__init__(src, dest, file_args, module) self.zipflag = 'j' + self.compress_mode = 'bz2' # class to handle xz compressed tar files @@ -608,6 +613,7 @@ class TarXzArchive(TgzArchive): def __init__(self, src, dest, file_args, module): super(TarXzArchive, self).__init__(src, dest, file_args, module) self.zipflag = 'J' + self.compress_mode = '' def _get_tar_fileobj(self): # Python's tarfile module doesn't support xz compression so we have to manually uncompress