From d1afcbced1c7c2de63a5b01d9fbd59e98d7fb117 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 10 Jul 2019 13:53:56 -0500 Subject: [PATCH] Cache handler name for included handlers. Fixes #58769 (#58780) --- .../fragments/58769-template-included-handler-names.yml | 3 +++ lib/ansible/plugins/strategy/__init__.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/58769-template-included-handler-names.yml diff --git a/changelogs/fragments/58769-template-included-handler-names.yml b/changelogs/fragments/58769-template-included-handler-names.yml new file mode 100644 index 00000000000..d6b83bc9960 --- /dev/null +++ b/changelogs/fragments/58769-template-included-handler-names.yml @@ -0,0 +1,3 @@ +bugfixes: +- handlers - Cache templated handler name on included handlers to avoid + later templating errors (https://github.com/ansible/ansible/issues/58769) diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index e46e6b1e3bf..f8a82d8d330 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -891,9 +891,13 @@ class StrategyBase: if not iterator.is_failed(host) or iterator._play.force_handlers: task_vars = self._variable_manager.get_vars(play=iterator._play, host=host, task=handler) self.add_tqm_variables(task_vars, play=iterator._play) + templar = Templar(loader=self._loader, variables=task_vars) + if not handler.cached_name: + handler.name = templar.template(handler.name) + handler.cached_name = True + self._queue_task(host, handler, task_vars, play_context) - templar = Templar(loader=self._loader, variables=task_vars) if templar.template(handler.run_once) or bypass_host_loop: break