delegation fix (#74685) (#74811)

(cherry picked from commit b518aabf81)
This commit is contained in:
Brian Coca 2021-06-14 15:58:02 -04:00 committed by GitHub
parent f752c7f179
commit e009cd9733
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Avoid task executor from ending early as vars can come from delegated to host.

View file

@ -5,7 +5,6 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import re
import pty
import time
import json
@ -20,7 +19,7 @@ from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVar
from ansible.executor.task_result import TaskResult
from ansible.executor.module_common import get_action_args_with_defaults
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import iteritems, string_types, binary_type
from ansible.module_utils.six import iteritems, binary_type
from ansible.module_utils.six.moves import xrange
from ansible.module_utils._text import to_text, to_native
from ansible.module_utils.connection import write_to_file_descriptor
@ -480,8 +479,8 @@ class TaskExecutor:
if self._loop_eval_error is not None:
raise self._loop_eval_error # pylint: disable=raising-bad-type
# if we ran into an error while setting up the PlayContext, raise it now
if context_validation_error is not None:
# if we ran into an error while setting up the PlayContext, raise it now, unless is known issue with delegation
if context_validation_error is not None and not (self._task.delegate_to and isinstance(context_validation_error, AnsibleUndefinedVariable)):
raise context_validation_error # pylint: disable=raising-bad-type
# if this task is a TaskInclude, we just return now with a success code so the

View file

@ -0,0 +1,18 @@
- name: ensure we can use fact on delegated host for connection info
hosts: localhost
gather_facts: no
tasks:
- add_host: name=f31 bogus_user=notme ansible_connection=ssh ansible_host=4.2.2.2
- name: if not overriding with delegated host info, will not be unreachable
ping:
timeout: 5
delegate_to: f31
ignore_errors: true
ignore_unreachable: true
register: delping
- name: ensure that the expected happened
assert:
that:
- delping is failed

View file

@ -74,3 +74,4 @@ ansible-playbook discovery_applied.yml -i inventory -v "$@"
ansible-playbook resolve_vars.yml -i inventory -v "$@"
ansible-playbook test_delegate_to_lookup_context.yml -i inventory -v "$@"
ansible-playbook delegate_local_from_root.yml -i inventory -v "$@" -e 'ansible_user=root'
ansible-playbook delegate_with_fact_from_delegate_host.yml "$@"