aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-05-18 19:13:01 +0200
committerGuido Günther <agx@sigxcpu.org>2016-05-18 19:13:01 +0200
commitfb47a568e0ce0724649f3e69c822a042316e7fb4 (patch)
tree7cdd11cce8fc24c3d8503272f0e7019d5fd330ff
parent5e496105e3ae434500daa20fe72f138d2669b4f0 (diff)
Improve error output if 'full_messages' is not present
In this case 'error' has the actual message
-rw-r--r--foremanhost.py8
1 files 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(