From 5a48c7ac7a9f8c493d2b809177b96e8c395369a4 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 18 Jan 2017 19:19:17 -0500 Subject: [PATCH] parse yaml metadata and more info on fragment err --- lib/ansible/utils/module_docs.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ansible/utils/module_docs.py b/lib/ansible/utils/module_docs.py index 36d8ccbcf7..4208d49767 100755 --- a/lib/ansible/utils/module_docs.py +++ b/lib/ansible/utils/module_docs.py @@ -104,7 +104,7 @@ def get_docstring(filename, verbose=False): doc['notes'].extend(notes) if 'options' not in fragment: - raise Exception("missing options in fragment, possibly misformatted?") + raise Exception("missing options in fragment (%s), possibly misformatted?: %s" % (fragment_name, filename)) for key, value in fragment.items(): if key not in doc: @@ -117,7 +117,7 @@ def get_docstring(filename, verbose=False): elif isinstance(doc[key], MutableSequence): doc[key] = sorted(frozenset(doc[key] + value)) else: - raise Exception("Attempt to extend a documentation fragement of unknown type") + raise Exception("Attempt to extend a documentation fragement (%s) of unknown type: %s" (fragment_name, filename)) elif 'EXAMPLES' == theid: plainexamples = child.value.s[1:] # Skip first empty line @@ -130,8 +130,12 @@ def get_docstring(filename, verbose=False): if type(metadata).__name__ == 'Dict': metadata = ast.literal_eval(child.value) else: - display.warning("Non-dict metadata detected in %s, skipping" % filename) - metadata = dict() + # try yaml loading + metadata = AnsibleLoader(child.value.s, file_name=filename).get_single_data() + + if not isinstance(metadata, dict): + display.warning("Invalid metadata detected in %s, using defaults" % filename) + metadata = {'status': ['preview'], 'supported_by': 'community', 'version': '1.0'} except: display.error("unable to parse %s" % filename)