diff --git a/changelogs/fragments/plugin-docs-list-fix.yaml b/changelogs/fragments/plugin-docs-list-fix.yaml new file mode 100644 index 00000000000..19ff8eef68a --- /dev/null +++ b/changelogs/fragments/plugin-docs-list-fix.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- 'Fixed an issue with ansible-doc -l failing when parsing some plugin documentation.' diff --git a/lib/ansible/parsing/plugin_docs.py b/lib/ansible/parsing/plugin_docs.py index dd1e038d9c4..fe0057f8a7a 100644 --- a/lib/ansible/parsing/plugin_docs.py +++ b/lib/ansible/parsing/plugin_docs.py @@ -90,18 +90,29 @@ def read_docstub(filename): """ t_module_data = open(filename, 'r') + in_documentation = False capturing = False + indent_detection = '' doc_stub = [] for line in t_module_data: - # start capturing the stub until indentation returns - if capturing and line[0] == ' ': - doc_stub.append(line) - elif capturing and line[0] != ' ': - break - if 'short_description:' in line: - capturing = True - doc_stub.append(line) + if in_documentation: + # start capturing the stub until indentation returns + if capturing and line.startswith(indent_detection): + doc_stub.append(line) + + elif capturing and not line.startswith(indent_detection): + break + + elif line.lstrip().startswith('short_description:'): + capturing = True + # Detect that the short_description continues on the next line if it's indented more + # than short_description itself. + indent_detection = ' ' * (len(line) - len(line.lstrip()) + 1) + doc_stub.append(line) + + elif line.startswith('DOCUMENTATION') and '=' in line: + in_documentation = True short_description = r''.join(doc_stub).strip().rstrip('.') data = AnsibleLoader(short_description, file_name=filename).get_single_data()