From 292c70368b3a05cf848bfc418c542b29d929aba9 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Wed, 1 Mar 2023 10:55:14 -0500 Subject: [PATCH] unarchive - log errors from underlying commands (#75329) * unarchive - log errors from underlying commands When a command run by the module fails, log the errors if debugging is enabled. * Use debug() method --- changelogs/fragments/64612-unarchive-log-command-output.yml | 2 ++ lib/ansible/modules/unarchive.py | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 changelogs/fragments/64612-unarchive-log-command-output.yml diff --git a/changelogs/fragments/64612-unarchive-log-command-output.yml b/changelogs/fragments/64612-unarchive-log-command-output.yml new file mode 100644 index 00000000000..0716fbb8d84 --- /dev/null +++ b/changelogs/fragments/64612-unarchive-log-command-output.yml @@ -0,0 +1,2 @@ +bugfixes: + - unarchive - log errors from commands to assist in debugging (https://github.com/ansible/ansible/issues/64612) diff --git a/lib/ansible/modules/unarchive.py b/lib/ansible/modules/unarchive.py index ceb8ca2a6b5..60147808b61 100644 --- a/lib/ansible/modules/unarchive.py +++ b/lib/ansible/modules/unarchive.py @@ -337,6 +337,7 @@ class ZipArchive(object): def _legacy_file_list(self): rc, out, err = self.module.run_command([self.cmd_path, '-v', self.src]) if rc: + self.module.debug(err) raise UnarchiveError('Neither python zipfile nor unzip can read %s' % self.src) for line in out.splitlines()[3:-2]: @@ -417,6 +418,7 @@ class ZipArchive(object): if self.include_files: cmd.extend(self.include_files) rc, out, err = self.module.run_command(cmd) + self.module.debug(err) old_out = out diff = '' @@ -745,6 +747,9 @@ class ZipArchive(object): rc, out, err = self.module.run_command(cmd) if rc == 0: return True, None + + self.module.debug(err) + return False, 'Command "%s" could not handle archive: %s' % (self.cmd_path, err) @@ -794,6 +799,7 @@ class TgzArchive(object): locale = get_best_parsable_locale(self.module) rc, out, err = self.module.run_command(cmd, cwd=self.b_dest, environ_update=dict(LANG=locale, LC_ALL=locale, LC_MESSAGES=locale, LANGUAGE=locale)) if rc != 0: + self.module.debug(err) raise UnarchiveError('Unable to list files in the archive: %s' % err) for filename in out.splitlines():