mirror of https://github.com/ansible/ansible.git
Plugin/module docs: parse return values, add collection names in them (version_added_collection), and format them nicely in ansible-doc (#69796)
* Tag return value docs if they are a dict (and not str/None). * Try to parse return docs as YAML. * Properly dump return values in ansible-doc. * Adjust plugin formatter. * Add changelog fragment. * Don't add 'default' for return values. * Fix plugin_formatter. * Only try to parse return docs if they are still a string. * Add tests. * Warn if RETURN cannot be parsed. * Adjust tests. Also test for warning. * if -> elif (otherwise EXAMPLE will be parsed too). * Always parse return documentation, and fail if it is invalid YAML. * Polishing. * Mostly re-enable ansible-doc tests. Listing from the local collection seems to be somewhat broken. I assume this is why the test was disabled. * Lint and make tests work with Python 2. * Keep FQCNs in plugins (not modules), i.e. restore previous state.pull/70021/head
parent
f509a22f9d
commit
8d93ba9120
@ -0,0 +1,4 @@
|
|||||||
|
minor_changes:
|
||||||
|
- "ansible-doc - return values will be properly formatted (https://github.com/ansible/ansible/pull/69796)."
|
||||||
|
major_changes:
|
||||||
|
- "Both ansible-doc and ansible-console's help command will error for modules and plugins whose return documentation cannot be parsed as YAML. All modules and plugins passing ``ansible-test sanity --test yamllint`` will not be affected by this."
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: test_docs_returns
|
||||||
|
short_description: Test module
|
||||||
|
description:
|
||||||
|
- Test module
|
||||||
|
author:
|
||||||
|
- Ansible Core Team
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
z_last:
|
||||||
|
description: A last result.
|
||||||
|
type: str
|
||||||
|
returned: success
|
||||||
|
|
||||||
|
m_middle:
|
||||||
|
description:
|
||||||
|
- This should be in the middle.
|
||||||
|
- Has some more data
|
||||||
|
type: dict
|
||||||
|
returned: success and 1st of month
|
||||||
|
contains:
|
||||||
|
suboption:
|
||||||
|
description: A suboption.
|
||||||
|
type: str
|
||||||
|
choices: [ARF, BARN, c_without_capital_first_letter]
|
||||||
|
|
||||||
|
a_first:
|
||||||
|
description: A first result.
|
||||||
|
type: str
|
||||||
|
returned: success
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
module.exit_json()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: test_docs_returns_broken
|
||||||
|
short_description: Test module
|
||||||
|
description:
|
||||||
|
- Test module
|
||||||
|
author:
|
||||||
|
- Ansible Core Team
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
test:
|
||||||
|
description: A test return value.
|
||||||
|
type: str
|
||||||
|
|
||||||
|
broken_key: [
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
module.exit_json()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
> TEST_DOCS_RETURNS (library/test_docs_returns.py)
|
||||||
|
|
||||||
|
Test module
|
||||||
|
|
||||||
|
AUTHOR: Ansible Core Team
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RETURN VALUES:
|
||||||
|
- a_first
|
||||||
|
A first result.
|
||||||
|
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
|
||||||
|
- m_middle
|
||||||
|
This should be in the middle.
|
||||||
|
Has some more data
|
||||||
|
|
||||||
|
returned: success and 1st of month
|
||||||
|
type: dict
|
||||||
|
|
||||||
|
CONTAINS:
|
||||||
|
|
||||||
|
- suboption
|
||||||
|
A suboption.
|
||||||
|
(Choices: ARF, BARN, c_without_capital_first_letter)
|
||||||
|
type: str
|
||||||
|
|
||||||
|
- z_last
|
||||||
|
A last result.
|
||||||
|
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
Loading…
Reference in New Issue