From fb47a568e0ce0724649f3e69c822a042316e7fb4 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Wed, 18 May 2016 19:13:01 +0200 Subject: Improve error output if 'full_messages' is not present In this case 'error' has the actual message --- foremanhost.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/foremanhost.py b/foremanhost.py index 47f7094..2dbb21e 100644 --- a/foremanhost.py +++ b/foremanhost.py @@ -370,9 +370,11 @@ def core(module): hid = item_to_id(host_url, 'name', name) else: try: - module.fail_json( - msg='Failed to create host %s: %s' % (name, e.response.json()['error']['full_messages']) - ) + if 'full_messages' in e.response.json()['error']: + msg = 'Failed to create host %s: %s' % (name, e.response.json()['error']['full_messages']) + else: + msg = 'Failed to create host %s: %s' % (name, e.response.json()['error']) + module.fail_json(msg=msg) # Catch any failures to get an error message except Exception as f: module.fail_json( -- cgit v1.2.3