Ensure we call action_loader.get with collection_list (#72206)

* Ensure we call action_loader.get with collection_list. Fixes #72170

* Add tests and changelog

* Remove grep, do assertion in playbook. ci_complete

* Skip old jinja2 versions

* ci_complete

* dedupe
This commit is contained in:
Matt Martz 2020-10-19 09:54:24 -05:00 committed by GitHub
parent 9ddb1d76af
commit be5fc4e642
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 4 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- Collections - Ensure ``action_loader.get`` is called with ``collection_list`` to properly find collections
when ``collections:`` search is specified (https://github.com/ansible/ansible/issues/72170)

View file

@ -738,7 +738,7 @@ class TaskExecutor:
# we need the 'normal' action handler for the status check, so get it
# now via the action_loader
async_handler = self._shared_loader_obj.action_loader.get(
'async_status',
'ansible.legacy.async_status',
task=async_task,
connection=self._connection,
play_context=self._play_context,

View file

@ -1016,7 +1016,7 @@ class StrategyBase:
bypass_host_loop = False
try:
action = plugin_loader.action_loader.get(handler.action, class_only=True)
action = plugin_loader.action_loader.get(handler.action, class_only=True, collection_list=handler.collections)
if getattr(action, 'BYPASS_HOST_LOOP', False):
bypass_host_loop = True
except KeyError:

View file

@ -156,7 +156,7 @@ class StrategyModule(StrategyBase):
(state, task) = iterator.get_next_task_for_host(host)
try:
action = action_loader.get(task.action, class_only=True)
action = action_loader.get(task.action, class_only=True, collection_list=task.collections)
except KeyError:
# we don't care here, because the action may simply not have a
# corresponding action plugin

View file

@ -265,7 +265,7 @@ class StrategyModule(StrategyBase):
task.action = templar.template(task.action)
try:
action = action_loader.get(task.action, class_only=True)
action = action_loader.get(task.action, class_only=True, collection_list=task.collections)
except KeyError:
# we don't care here, because the action may simply not have a
# corresponding action plugin

View file

@ -0,0 +1,17 @@
# Copyright: (c) 2020, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.plugins.action import ActionBase
class ActionModule(ActionBase):
BYPASS_HOST_LOOP = True
def run(self, tmp=None, task_vars=None):
result = super(ActionModule, self).run(tmp, task_vars)
result['bypass_inventory_hostname'] = task_vars['inventory_hostname']
return result

View file

@ -68,6 +68,9 @@ if [[ ${INVENTORY_PATH} != *.winrm ]]; then
ansible-playbook -i "${INVENTORY_PATH}" -v invocation_tests.yml "$@"
fi
echo "--- validating bypass_host_loop with collection search"
ansible-playbook -i host1,host2, -v test_bypass_host_loop.yml "$@"
echo "--- validating inventory"
# test collection inventories
ansible-playbook inventory_test.yml -i a.statichost.yml -i redirected.statichost.yml "$@"

View file

@ -0,0 +1,22 @@
- name: Test collection lookup bypass host list
hosts: all
connection: local
gather_facts: false
collections:
- testns.testcoll
tasks:
- meta: end_host
when: lookup('pipe', ansible_playbook_python ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.7', '<')
- bypass_host_loop:
register: bypass
- run_once: true
vars:
bypass_hosts: '{{ hostvars|dictsort|map(attribute="1.bypass.bypass_inventory_hostname")|select("defined")|unique }}'
block:
- debug:
var: bypass_hosts
- assert:
that: bypass_hosts|length == 1