Remove deprecated vars plugin fallback (#85809)

* Remove deprecated vars plugin fallback

Removes the vars plugin `get_host_vars` and `get_group_vars` fallback
which was deprecated.

* Remove integration tests for removed feature
pull/85808/head
Jordan Borean 3 months ago committed by GitHub
parent 94c78cb38f
commit 3582997698
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,4 @@
removed_features:
- >-
vars plugins - removed the deprecated ``get_host_vars`` or ``get_group_vars`` fallback for vars plugins that do
not inherit from ``BaseVarsPlugin`` and define a ``get_vars`` method.

@ -8,8 +8,6 @@ import os
from functools import lru_cache from functools import lru_cache
from ansible import constants as C from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.inventory.group import InventoryObjectType
from ansible.plugins.loader import vars_loader from ansible.plugins.loader import vars_loader
from ansible.utils.display import Display from ansible.utils.display import Display
from ansible.utils.vars import combine_vars from ansible.utils.vars import combine_vars
@ -26,34 +24,6 @@ def _prime_vars_loader():
vars_loader.get(plugin_name) vars_loader.get(plugin_name)
def get_plugin_vars(loader, plugin, path, entities):
data = {}
try:
data = plugin.get_vars(loader, path, entities)
except AttributeError:
if hasattr(plugin, 'get_host_vars') or hasattr(plugin, 'get_group_vars'):
display.deprecated(
msg=f"The vars plugin {plugin.ansible_name} from {plugin._original_path} is relying "
"on the deprecated entrypoints `get_host_vars` and `get_group_vars`.",
version="2.20",
help_text="This plugin should be updated to inherit from `BaseVarsPlugin` and define "
"a `get_vars` method as the main entrypoint instead.",
)
try:
for entity in entities:
if entity.base_type is InventoryObjectType.HOST:
data |= plugin.get_host_vars(entity.name)
else:
data |= plugin.get_group_vars(entity.name)
except AttributeError:
if hasattr(plugin, 'run'):
raise AnsibleError("Cannot use v1 type vars plugin %s from %s" % (plugin._load_name, plugin._original_path))
else:
raise AnsibleError("Invalid vars plugin %s from %s" % (plugin._load_name, plugin._original_path))
return data
# optimized for stateless plugins; non-stateless plugin instances will fall out quickly # optimized for stateless plugins; non-stateless plugin instances will fall out quickly
@lru_cache(maxsize=10) @lru_cache(maxsize=10)
def _plugin_should_run(plugin, stage): def _plugin_should_run(plugin, stage):
@ -99,7 +69,7 @@ def get_vars_from_path(loader, path, entities, stage):
if not _plugin_should_run(plugin, stage): if not _plugin_should_run(plugin, stage):
continue continue
if (new_vars := get_plugin_vars(loader, plugin, path, entities)) != {}: if (new_vars := plugin.get_vars(loader, path, entities)) != {}:
data = combine_vars(data, new_vars) data = combine_vars(data, new_vars)
return data return data

@ -1,9 +0,0 @@
from __future__ import annotations
class VarsModule:
def get_host_vars(self, entity):
return {}
def get_group_vars(self, entity):
return {}

@ -12,13 +12,6 @@ export ANSIBLE_VARS_PLUGINS=./vars_plugins
export ANSIBLE_VARS_ENABLED=require_enabled export ANSIBLE_VARS_ENABLED=require_enabled
[ "$(ansible-inventory -i localhost, --list --yaml all "$@" | grep -c 'require_enabled')" = "1" ] [ "$(ansible-inventory -i localhost, --list --yaml all "$@" | grep -c 'require_enabled')" = "1" ]
# Test deprecated features
export ANSIBLE_VARS_PLUGINS=./deprecation_warning
WARNING="The vars plugin v2_vars_plugin .* is relying on the deprecated entrypoints \`get_host_vars\` and \`get_group_vars\`"
ANSIBLE_DEPRECATION_WARNINGS=True ANSIBLE_NOCOLOR=True ANSIBLE_FORCE_COLOR=False \
ansible-inventory -i localhost, --list all "$@" 2> err.txt
ansible localhost -m debug -a "msg={{ lookup('file', 'err.txt') | regex_replace('\n', '') }}" | grep "$WARNING"
# Test how many times vars plugins are loaded for a simple play containing a task # Test how many times vars plugins are loaded for a simple play containing a task
# host_group_vars is stateless, so we can load it once and reuse it, every other vars plugin should be instantiated before it runs # host_group_vars is stateless, so we can load it once and reuse it, every other vars plugin should be instantiated before it runs
cat << EOF > "test_task_vars.yml" cat << EOF > "test_task_vars.yml"

@ -232,5 +232,4 @@ test/integration/targets/ansible-test-sanity-pylint/deprecated_thing.py pylint:a
lib/ansible/galaxy/api.py pylint:ansible-deprecated-version # TODO: 2.20 lib/ansible/galaxy/api.py pylint:ansible-deprecated-version # TODO: 2.20
lib/ansible/utils/encrypt.py pylint:ansible-deprecated-version # TODO: 2.20 lib/ansible/utils/encrypt.py pylint:ansible-deprecated-version # TODO: 2.20
lib/ansible/vars/manager.py pylint:ansible-deprecated-version-comment # TODO: 2.20 lib/ansible/vars/manager.py pylint:ansible-deprecated-version-comment # TODO: 2.20
lib/ansible/vars/plugins.py pylint:ansible-deprecated-version # TODO: 2.20
lib/ansible/galaxy/role.py pylint:ansible-deprecated-python-version-comment # TODO: 2.20 lib/ansible/galaxy/role.py pylint:ansible-deprecated-python-version-comment # TODO: 2.20

Loading…
Cancel
Save