From 16ca412bd700ff88bbfbed250be439e043035282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Stankovi=C4=87?= Date: Wed, 13 Sep 2017 15:33:37 +0200 Subject: [PATCH] xml module: Improve error message for missing namespaces --- lib/ansible/modules/files/xml.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/files/xml.py b/lib/ansible/modules/files/xml.py index df1a53947fe..389a87b0528 100644 --- a/lib/ansible/modules/files/xml.py +++ b/lib/ansible/modules/files/xml.py @@ -545,8 +545,11 @@ def set_target_inner(module, tree, xpath, namespaces, attribute, value): if not is_node(tree, xpath, namespaces): changed = check_or_make_target(module, tree, xpath, namespaces) except Exception as e: - module.fail_json(msg="Xpath %s causes a failure: %s\n -- tree is %s" % - (xpath, e, etree.tostring(tree, pretty_print=True)), exception=traceback.format_exc(e)) + missing_namespace = "" + if len(tree.getroot().nsmap) > 0 and ":" not in xpath: + missing_namespace = "XML document has namespace(s) defined, but no namespace prefix(es) used in xpath!\n" + module.fail_json(msg="%sXpath %s causes a failure: %s\n -- tree is %s" % + (missing_namespace, xpath, e, etree.tostring(tree, pretty_print=True)), exception=traceback.format_exc()) if not is_node(tree, xpath, namespaces): module.fail_json(msg="Xpath %s does not reference a node! tree is %s" %