From 0b0acef42311062deecc68368db1db1d8439b1bf Mon Sep 17 00:00:00 2001 From: "Jonas I. Liechti" Date: Thu, 28 Oct 2021 15:06:51 +0000 Subject: [PATCH] bug fix: using non-FQDN in plugin choices fails plugin name verification (#75991) * enable both non-FQDN and FQDN plugin name * add info about matching requirement of plugin name in config and plugin source file --- docs/docsite/rst/plugins/inventory.rst | 1 + lib/ansible/plugins/inventory/constructed.py | 4 ++-- lib/ansible/plugins/inventory/generator.py | 4 ++-- test/integration/targets/inventory/1/2/inventory.yml | 2 +- test/integration/targets/inventory/extra_vars_constructed.yml | 2 +- .../integration/targets/inventory_constructed/constructed.yml | 2 +- .../targets/inventory_constructed/invs/2/constructed.yml | 2 +- .../inventory_constructed/keyed_group_default_value.yml | 2 +- .../inventory_constructed/keyed_group_list_default_value.yml | 4 ++-- .../inventory_constructed/keyed_group_str_default_value.yml | 4 ++-- .../inventory_constructed/keyed_group_trailing_separator.yml | 2 +- .../no_leading_separator_constructed.yml | 2 +- 12 files changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/docsite/rst/plugins/inventory.rst b/docs/docsite/rst/plugins/inventory.rst index 22231086f15..8e2ade376ad 100644 --- a/docs/docsite/rst/plugins/inventory.rst +++ b/docs/docsite/rst/plugins/inventory.rst @@ -30,6 +30,7 @@ If the plugin is in a collection, use the fully qualified name: [inventory] enable_plugins = namespace.collection_name.inventory_plugin_name +If you use a plugin that supports a YAML configuration source, make sure that the name matches the name provided in the ``plugin`` entry of the inventory source file. .. _using_inventory: diff --git a/lib/ansible/plugins/inventory/constructed.py b/lib/ansible/plugins/inventory/constructed.py index b94dad4fa0e..dd630c66cd2 100644 --- a/lib/ansible/plugins/inventory/constructed.py +++ b/lib/ansible/plugins/inventory/constructed.py @@ -18,7 +18,7 @@ DOCUMENTATION = ''' plugin: description: token that ensures this is a source file for the 'constructed' plugin. required: True - choices: ['constructed'] + choices: ['ansible.builtin.constructed', 'constructed'] use_vars_plugins: description: - Normally, for performance reasons, vars plugins get executed after the inventory sources complete the base inventory, @@ -36,7 +36,7 @@ DOCUMENTATION = ''' EXAMPLES = r''' # inventory.config file in YAML format - plugin: constructed + plugin: ansible.builtin.constructed strict: False compose: var_sum: var1 + var2 diff --git a/lib/ansible/plugins/inventory/generator.py b/lib/ansible/plugins/inventory/generator.py index 27575dd0c71..1955f361df9 100644 --- a/lib/ansible/plugins/inventory/generator.py +++ b/lib/ansible/plugins/inventory/generator.py @@ -17,7 +17,7 @@ DOCUMENTATION = ''' plugin: description: token that ensures this is a source file for the 'generator' plugin. required: True - choices: ['generator'] + choices: ['ansible.builtin.generator', 'generator'] hosts: description: - The C(name) key is a template used to generate @@ -39,7 +39,7 @@ EXAMPLES = ''' # inventory.config file in YAML format # remember to enable this inventory plugin in the ansible.cfg before using # View the output using `ansible-inventory -i inventory.config --list` - plugin: generator + plugin: ansible.builtin.generator hosts: name: "{{ operation }}_{{ application }}_{{ environment }}_runner" parents: diff --git a/test/integration/targets/inventory/1/2/inventory.yml b/test/integration/targets/inventory/1/2/inventory.yml index 5082cef2f2e..b6c31ad8689 100644 --- a/test/integration/targets/inventory/1/2/inventory.yml +++ b/test/integration/targets/inventory/1/2/inventory.yml @@ -1,3 +1,3 @@ -plugin: constructed +plugin: ansible.builtin.constructed groups: webservers: inventory_hostname.startswith('web') diff --git a/test/integration/targets/inventory/extra_vars_constructed.yml b/test/integration/targets/inventory/extra_vars_constructed.yml index 66bee863fbd..ee6f5fd6a0c 100644 --- a/test/integration/targets/inventory/extra_vars_constructed.yml +++ b/test/integration/targets/inventory/extra_vars_constructed.yml @@ -1,4 +1,4 @@ -plugin: constructed +plugin: ansible.builtin.constructed strict: true use_extra_vars: True compose: diff --git a/test/integration/targets/inventory_constructed/constructed.yml b/test/integration/targets/inventory_constructed/constructed.yml index baeea323f7b..be02858f1b4 100644 --- a/test/integration/targets/inventory_constructed/constructed.yml +++ b/test/integration/targets/inventory_constructed/constructed.yml @@ -1,4 +1,4 @@ -plugin: constructed +plugin: ansible.builtin.constructed keyed_groups: - key: hostvar0 - key: hostvar1 diff --git a/test/integration/targets/inventory_constructed/invs/2/constructed.yml b/test/integration/targets/inventory_constructed/invs/2/constructed.yml index 7c62ef1de54..ca26e2c960b 100644 --- a/test/integration/targets/inventory_constructed/invs/2/constructed.yml +++ b/test/integration/targets/inventory_constructed/invs/2/constructed.yml @@ -1,4 +1,4 @@ -plugin: constructed +plugin: ansible.builtin.constructed use_vars_plugins: true keyed_groups: - key: iamdefined diff --git a/test/integration/targets/inventory_constructed/keyed_group_default_value.yml b/test/integration/targets/inventory_constructed/keyed_group_default_value.yml index e4d0a76b7ea..d69e8ec5657 100644 --- a/test/integration/targets/inventory_constructed/keyed_group_default_value.yml +++ b/test/integration/targets/inventory_constructed/keyed_group_default_value.yml @@ -1,4 +1,4 @@ -plugin: constructed +plugin: ansible.builtin.constructed keyed_groups: - key: tags prefix: tag diff --git a/test/integration/targets/inventory_constructed/keyed_group_list_default_value.yml b/test/integration/targets/inventory_constructed/keyed_group_list_default_value.yml index 1c2d00e06ee..4481db31869 100644 --- a/test/integration/targets/inventory_constructed/keyed_group_list_default_value.yml +++ b/test/integration/targets/inventory_constructed/keyed_group_list_default_value.yml @@ -1,5 +1,5 @@ -plugin: constructed +plugin: ansible.builtin.constructed keyed_groups: - key: roles default_value: storage - prefix: host \ No newline at end of file + prefix: host diff --git a/test/integration/targets/inventory_constructed/keyed_group_str_default_value.yml b/test/integration/targets/inventory_constructed/keyed_group_str_default_value.yml index ae3fd5ae392..256d33093c3 100644 --- a/test/integration/targets/inventory_constructed/keyed_group_str_default_value.yml +++ b/test/integration/targets/inventory_constructed/keyed_group_str_default_value.yml @@ -1,5 +1,5 @@ -plugin: constructed +plugin: ansible.builtin.constructed keyed_groups: - key: os default_value: "fedora" - prefix: host \ No newline at end of file + prefix: host diff --git a/test/integration/targets/inventory_constructed/keyed_group_trailing_separator.yml b/test/integration/targets/inventory_constructed/keyed_group_trailing_separator.yml index cbe57c6098e..d69899dbf51 100644 --- a/test/integration/targets/inventory_constructed/keyed_group_trailing_separator.yml +++ b/test/integration/targets/inventory_constructed/keyed_group_trailing_separator.yml @@ -1,4 +1,4 @@ -plugin: constructed +plugin: ansible.builtin.constructed keyed_groups: - key: tags prefix: tag diff --git a/test/integration/targets/inventory_constructed/no_leading_separator_constructed.yml b/test/integration/targets/inventory_constructed/no_leading_separator_constructed.yml index 5f35de14088..5ff8f9333ff 100644 --- a/test/integration/targets/inventory_constructed/no_leading_separator_constructed.yml +++ b/test/integration/targets/inventory_constructed/no_leading_separator_constructed.yml @@ -1,4 +1,4 @@ -plugin: constructed +plugin: ansible.builtin.constructed keyed_groups: - key: hostvar0 - key: hostvar1