diff --git a/changelogs/fragments/fix-metadata-defaults.yml b/changelogs/fragments/fix-metadata-defaults.yml new file mode 100644 index 00000000000..e12f00c4667 --- /dev/null +++ b/changelogs/fragments/fix-metadata-defaults.yml @@ -0,0 +1,5 @@ +bugfixes: +- Plugin Metadata is supposed to have default values. When the metadata was + missing entirely, we were properly setting the defaults. Fixed the metadata + parsing so that the defaults are also set when we were missing just a few + fields. diff --git a/lib/ansible/parsing/plugin_docs.py b/lib/ansible/parsing/plugin_docs.py index 73945306c24..4f036127e0f 100644 --- a/lib/ansible/parsing/plugin_docs.py +++ b/lib/ansible/parsing/plugin_docs.py @@ -67,9 +67,16 @@ def read_docstring(filename, verbose=True, ignore_errors=True): if data['metadata']: # remove version - for x in ('version', 'metadata_version'): - if x in data['metadata']: - del data['metadata'][x] + for field in ('version', 'metadata_version'): + if field in data['metadata']: + del data['metadata'][field] + + if 'supported_by' not in data['metadata']: + data['metadata']['supported_by'] = 'community' + + if 'status' not in data['metadata']: + data['metadata']['status'] = ['preview'] + else: # Add default metadata data['metadata'] = {'supported_by': 'community', diff --git a/test/integration/targets/ansible-doc/test.yml b/test/integration/targets/ansible-doc/test.yml index a6944c44622..1781caad46b 100644 --- a/test/integration/targets/ansible-doc/test.yml +++ b/test/integration/targets/ansible-doc/test.yml @@ -85,8 +85,8 @@ register: result - assert: that: - - 'result is failed' - - '"ERROR! module test_no_docs_no_status missing documentation (or could not parse documentation): test_no_docs_no_status did not contain a DOCUMENTATION attribute" in result.stderr' + - 'result.stdout == ""' + - 'result.stderr == ""' - name: module with no documentation and non-iterable status in metadata command: ansible-doc test_no_docs_non_iterable_status