From 64bb54dab402b68b97e0c3cd7a72ae2b5e9b866e Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 20 Nov 2018 14:29:44 -0600 Subject: [PATCH] Catch per loop label templating exceptions. Fixes #48879 (#48896) --- .../fragments/loop-control-label-template-error.yaml | 5 +++++ lib/ansible/executor/task_executor.py | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/loop-control-label-template-error.yaml diff --git a/changelogs/fragments/loop-control-label-template-error.yaml b/changelogs/fragments/loop-control-label-template-error.yaml new file mode 100644 index 00000000000..f8711f8724e --- /dev/null +++ b/changelogs/fragments/loop-control-label-template-error.yaml @@ -0,0 +1,5 @@ +bugfixes: +- loop_control - Catch exceptions when templating label individually for loop + iterations which caused the templating failure as the full + result. This instead only registers the templating exception for a single + loop result (https://github.com/ansible/ansible/issues/48879) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index af928fe5aa6..3d94531bb39 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -361,7 +361,13 @@ class TaskExecutor: res['_ansible_ignore_errors'] = task_fields.get('ignore_errors') # gets templated here unlike rest of loop_control fields, depends on loop_var above - res['_ansible_item_label'] = templar.template(label, cache=False) + try: + res['_ansible_item_label'] = templar.template(label, cache=False) + except AnsibleUndefinedVariable as e: + res.update({ + 'failed': True, + 'msg': 'Failed to template loop_control.label: %s' % to_text(e) + }) self._final_q.put( TaskResult(