From 76d74a8fe527dbe410475c165368a38fd03d5650 Mon Sep 17 00:00:00 2001 From: laszlojau <49835454+laszlojau@users.noreply.github.com> Date: Sat, 17 Jun 2023 21:55:48 +0930 Subject: [PATCH] Raise a warning when the attachment can't be read --- plugins/lookup/tss.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/lookup/tss.py b/plugins/lookup/tss.py index fb6fad4f37..03f5c03627 100644 --- a/plugins/lookup/tss.py +++ b/plugins/lookup/tss.py @@ -289,11 +289,14 @@ class TSSClient(object): if file_download_path and os.path.isdir(file_download_path): if i['isFile']: try: + file_content = i['itemValue'].content with open(os.path.join(file_download_path, str(obj['id']) + "_" + i['slug']), "wb") as f: - f.write(i['itemValue'].content) + f.write(file_content) i['itemValue'] = "*** Not Valid For Display ***" except ValueError: raise AnsibleOptionsError("Failed to download {0}".format(str(i['slug']))) + except AttributeError: + display.warning("Could not read file content for {0}".format(str(i['slug']))) else: raise AnsibleOptionsError("File download path does not exist") return obj