diff --git a/lib/ansible/modules/files/xml.py b/lib/ansible/modules/files/xml.py index df1a53947f..389a87b052 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" %