diff --git a/library/files/unarchive b/library/files/unarchive index ab04e57475c..29e9ddb9e48 100644 --- a/library/files/unarchive +++ b/library/files/unarchive @@ -81,17 +81,20 @@ class ZipFile(object): self.src = src self.dest = dest self.module = module + self.cmd_path = self.module.get_bin_path('unzip') def is_unarchived(self): return dict(unarchived=False) def unarchive(self): - cmd = 'unzip -o "%s" -d "%s"' % (self.src, self.dest) + cmd = '%s -o "%s" -d "%s"' % (self.cmd_path, self.src, self.dest) rc, out, err = self.module.run_command(cmd) return dict(cmd=cmd, rc=rc, out=out, err=err) def can_handle_archive(self): - cmd = 'unzip -l "%s"' % self.src + if not self.cmd_path: + return False + cmd = '%s -l "%s"' % (self.cmd_path, self.src) rc, out, err = self.module.run_command(cmd) if rc == 0: return True @@ -105,23 +108,26 @@ class TgzFile(object): self.src = src self.dest = dest self.module = module + self.cmd_path = self.module.get_bin_path('tar') self.zipflag = 'z' def is_unarchived(self): dirof = os.path.dirname(self.dest) destbase = os.path.basename(self.dest) - cmd = 'tar -v -C "%s" --diff -%sf "%s"' % (self.dest, self.zipflag, self.src) + cmd = '%s -v -C "%s" --diff -%sf "%s"' % (self.cmd_path, self.dest, self.zipflag, self.src) rc, out, err = self.module.run_command(cmd) unarchived = (rc == 0) return dict(unarchived=unarchived, rc=rc, out=out, err=err, cmd=cmd) def unarchive(self): - cmd = 'tar -C "%s" -x%sf "%s"' % (self.dest, self.zipflag, self.src) + cmd = '%s -C "%s" -x%sf "%s"' % (self.cmd_path, self.dest, self.zipflag, self.src) rc, out, err = self.module.run_command(cmd) return dict(cmd=cmd, rc=rc, out=out, err=err) def can_handle_archive(self): - cmd = 'tar -t%sf "%s"' % (self.zipflag, self.src) + if not self.cmd_path: + return False + cmd = '%s -t%sf "%s"' % (self.cmd_path, self.zipflag, self.src) rc, out, err = self.module.run_command(cmd) if rc == 0: if len(out.splitlines(True)) > 0: @@ -135,6 +141,7 @@ class TarFile(TgzFile): self.src = src self.dest = dest self.module = module + self.cmd_path = self.module.get_bin_path('tar') self.zipflag = '' @@ -144,6 +151,7 @@ class TarBzip(TgzFile): self.src = src self.dest = dest self.module = module + self.cmd_path = self.module.get_bin_path('tar') self.zipflag = 'j' @@ -153,6 +161,7 @@ class TarXz(TgzFile): self.src = src self.dest = dest self.module = module + self.cmd_path = self.module.get_bin_path('tar') self.zipflag = 'J' @@ -163,7 +172,7 @@ def pick_handler(src, dest, module): obj = handler(src, dest, module) if obj.can_handle_archive(): return obj - raise RuntimeError('Failed to find handler to unarchive "%s"' % src) + module.fail_json(msg='Failed to find handler to unarchive. Make sure the required command to extract the file is installed.') def main():