From 36916f862280c17e394eacaf59be9c48a5781335 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 24 Feb 2016 10:29:35 -0600 Subject: [PATCH] Return useful error messages on requests exception We need to be able to debug this. Change-Id: Ie20bc1293d80bbbd45479c12dd65314b27c61e40 --- library/puppet_post_puppetdb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/library/puppet_post_puppetdb b/library/puppet_post_puppetdb index 0136adc..14cb1db 100644 --- a/library/puppet_post_puppetdb +++ b/library/puppet_post_puppetdb @@ -120,10 +120,25 @@ def main(): payload_dump = p['logfile'][:-4] + "facts_payload.json" with open(payload_dump, 'w') as f: f.write(json.dumps(payload)) - r = requests.post(endpoint, json=payload, **requests_kwargs) + try: + r = requests.post(endpoint, json=payload, **requests_kwargs) + except Exception as e: + module.fail_json( + msg="Exception: {e}".format(e=e), + puppetdb=p['puppetdb'], + endpoint=endpoint, + logfile=payload_dump) log_data = json.load(open(p['logfile'], 'r')) - r = requests.post(endpoint, json=log_data, **requests_kwargs) + try: + r = requests.post(endpoint, json=log_data, **requests_kwargs) + except Exception as e: + module.fail_json( + msg="Exception: {e}".format(e=e), + puppetdb=p['puppetdb'], + endpoint=endpoint, + logfile=p['logfile']) + if r.status_code != 200: module.fail_json( rc=r.status_code,