summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2021-06-14 15:58:02 -0400
committerGitHub <noreply@github.com>2021-06-14 14:58:02 -0500
commite009cd9733347f4a124f8a860419a8b3f737464e (patch)
tree68ec017d286d4c2a72837b49d8c677c794c9d0d3
parentf752c7f179e3090d794ec09d4d6c544548897c4b (diff)
downloadansible-e009cd9733347f4a124f8a860419a8b3f737464e.tar.gz
delegation fix (#74685) (#74811)
(cherry picked from commit b518aabf81213dd4d8b5b46a1a0657b5d8408238)
-rw-r--r--changelogs/fragments/delegate_te_fix.yml2
-rw-r--r--lib/ansible/executor/task_executor.py7
-rw-r--r--test/integration/targets/delegate_to/delegate_with_fact_from_delegate_host.yml18
-rwxr-xr-xtest/integration/targets/delegate_to/runme.sh1
4 files changed, 24 insertions, 4 deletions
diff --git a/changelogs/fragments/delegate_te_fix.yml b/changelogs/fragments/delegate_te_fix.yml
new file mode 100644
index 0000000000..cfbdb2ed3d
--- /dev/null
+++ b/changelogs/fragments/delegate_te_fix.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - Avoid task executor from ending early as vars can come from delegated to host.
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index cb5ad09ad4..7ee809af41 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 0000000000..1670398423
--- /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 0ec570b44c..af090cdf02 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 "$@"