From b518aabf81213dd4d8b5b46a1a0657b5d8408238 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 24 May 2021 10:13:19 -0400 Subject: [PATCH] delegation fix (#74685) * delegation fix --- lib/ansible/executor/task_executor.py | 7 +++---- .../delegate_with_fact_from_delegate_host.yml | 18 ++++++++++++++++++ test/integration/targets/delegate_to/runme.sh | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/integration/targets/delegate_to/delegate_with_fact_from_delegate_host.yml diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 781394fa96b..b798c3d9a4f 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -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 diff --git a/test/integration/targets/delegate_to/delegate_with_fact_from_delegate_host.yml b/test/integration/targets/delegate_to/delegate_with_fact_from_delegate_host.yml new file mode 100644 index 00000000000..16703984232 --- /dev/null +++ b/test/integration/targets/delegate_to/delegate_with_fact_from_delegate_host.yml @@ -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 diff --git a/test/integration/targets/delegate_to/runme.sh b/test/integration/targets/delegate_to/runme.sh index 0ec570b44cd..af090cdf024 100755 --- a/test/integration/targets/delegate_to/runme.sh +++ b/test/integration/targets/delegate_to/runme.sh @@ -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 "$@"