improve inv plugin selectino for snippets (#74933)

* improve inv plugin selectino for snippets
* add warning on no snippet for inventory
pull/74959/head
Brian Coca 3 years ago committed by GitHub
parent 346c7a765d
commit 1c4ca154fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- ansible-doc, make inventory plugin selection for snippets generic and not a hardcoded list

@ -842,8 +842,9 @@ class DocCLI(CLI, RoleMixin):
if context.CLIARGS['show_snippet']:
if plugin_type not in SNIPPETS:
raise AnsibleError("Snippets are only available for the following plugin types: %s" % ', '.join(SNIPPETS))
if plugin_type == 'inventory' and plugin in ('yaml', 'toml'):
# not usable as other inventory plugins
if plugin_type == 'inventory' and doc.get('options') and not doc['options'].get('plugin'):
# these are 'configurable' but not intended for yaml type inventory sources, like ini or script
# so we cannot use as source for snippets
del doc['options']
text = DocCLI.get_snippet_text(doc, plugin_type)
else:
@ -971,6 +972,8 @@ class DocCLI(CLI, RoleMixin):
_do_lookup_snippet(text, doc)
elif 'options' in doc:
_do_yaml_snippet(text, doc)
elif ptype == 'inventory':
display.warning('Snippets are only available to inventory plugins with YAML type sources that can be used with the "auto" plugin.')
text.append('')
return "\n".join(text)

Loading…
Cancel
Save