From f2ccc45c067c82fa2590a91150c5bddebff54445 Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Mon, 8 Aug 2022 10:18:28 +0200 Subject: [PATCH] Supply missing error message on S3 upload failure The `fail_json()` method of the Ansible module expects a msg argument. https://docs.ansible.com/ansible/latest/reference_appendices/module_utils.html Traceback (most recent call last): File \\"\\", line 102, in File \\"\\", line 94, in _ansiballz_main File \\"\\", line 40, in invoke_module File \\"/usr/local/lib/python3.10/runpy.py\\", line 224, in run_module return _run_module_code(code, init_globals, run_name, mod_spec) File \\"/usr/local/lib/python3.10/runpy.py\\", line 96, in _run_module_code _run_code(code, mod_globals, init_globals, File \\"/usr/local/lib/python3.10/runpy.py\\", line 86, in _run_code exec(code, run_globals) File \\"/var/cache/zuul-executor/jobs/2f077ccd11b844e587a4d220ed22f36c/work/tmp/ansible_zuul_s3_upload_payload_l3h9evxc/ansible_zuul_s3_upload_payload.zip/ansible/modules/zuul_s3_upload.py\\", line 366, in File \\"/var/cache/zuul-executor/jobs/2f077ccd11b844e587a4d220ed22f36c/work/tmp/ansible_zuul_s3_upload_payload_l3h9evxc/ansible_zuul_s3_upload_payload.zip/ansible/modules/zuul_s3_upload.py\\", line 313, in ansible_main File \\"/var/cache/zuul-executor/jobs/2f077ccd11b844e587a4d220ed22f36c/work/tmp/ansible_zuul_s3_upload_payload_l3h9evxc/ansible_zuul_s3_upload_payload.zip/ansible/module_utils/basic.py\\", line 2183, in fail_json AssertionError: implementation error -- msg to explain the error is required Change-Id: I30a50ebd3c4a2553142a67ecb1bbb1faa2b3c527 --- roles/upload-logs-base/library/zuul_s3_upload.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/roles/upload-logs-base/library/zuul_s3_upload.py b/roles/upload-logs-base/library/zuul_s3_upload.py index 8d2bc4278..50ea28823 100755 --- a/roles/upload-logs-base/library/zuul_s3_upload.py +++ b/roles/upload-logs-base/library/zuul_s3_upload.py @@ -27,6 +27,7 @@ Utility to upload files to s3 import argparse import logging import os +import pprint try: import queue as queuelib except ImportError: @@ -259,7 +260,9 @@ def ansible_main(): aws_access_key=p.get('aws_access_key'), aws_secret_key=p.get('aws_secret_key')) if failures: - module.fail_json(changed=True, + failure_msg = pprint.pformat(failures) + module.fail_json(msg=f"Failure(s) during log upload:\n{failure_msg}", + changed=True, url=url, failures=failures) module.exit_json(changed=True,