improve inv plugin selectino for snippets (#74933)
* improve inv plugin selectino for snippets * add warning on no snippet for inventory
This commit is contained in:
parent
346c7a765d
commit
1c4ca154fa
2 changed files with 7 additions and 2 deletions
2
changelogs/fragments/snippets_inv_select.yml
Normal file
2
changelogs/fragments/snippets_inv_select.yml
Normal file
|
@ -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 context.CLIARGS['show_snippet']:
|
||||||
if plugin_type not in SNIPPETS:
|
if plugin_type not in SNIPPETS:
|
||||||
raise AnsibleError("Snippets are only available for the following plugin types: %s" % ', '.join(SNIPPETS))
|
raise AnsibleError("Snippets are only available for the following plugin types: %s" % ', '.join(SNIPPETS))
|
||||||
if plugin_type == 'inventory' and plugin in ('yaml', 'toml'):
|
if plugin_type == 'inventory' and doc.get('options') and not doc['options'].get('plugin'):
|
||||||
# not usable as other inventory plugins
|
# 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']
|
del doc['options']
|
||||||
text = DocCLI.get_snippet_text(doc, plugin_type)
|
text = DocCLI.get_snippet_text(doc, plugin_type)
|
||||||
else:
|
else:
|
||||||
|
@ -971,6 +972,8 @@ class DocCLI(CLI, RoleMixin):
|
||||||
_do_lookup_snippet(text, doc)
|
_do_lookup_snippet(text, doc)
|
||||||
elif 'options' in doc:
|
elif 'options' in doc:
|
||||||
_do_yaml_snippet(text, 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('')
|
text.append('')
|
||||||
return "\n".join(text)
|
return "\n".join(text)
|
||||||
|
|
Loading…
Reference in a new issue