From 1c4ca154fabffb706f8227054ddaa59e744001ef Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 9 Jun 2021 12:13:56 -0400 Subject: [PATCH] improve inv plugin selectino for snippets (#74933) * improve inv plugin selectino for snippets * add warning on no snippet for inventory --- changelogs/fragments/snippets_inv_select.yml | 2 ++ lib/ansible/cli/doc.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/snippets_inv_select.yml diff --git a/changelogs/fragments/snippets_inv_select.yml b/changelogs/fragments/snippets_inv_select.yml new file mode 100644 index 00000000000..2aca2dfc35d --- /dev/null +++ b/changelogs/fragments/snippets_inv_select.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-doc, make inventory plugin selection for snippets generic and not a hardcoded list diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index 14f8a696e08..6f86d12898c 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -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)