From afcc9ddf8c0fef2860979381e220b3b47db2d33b Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 20 Apr 2018 11:18:04 -0500 Subject: [PATCH] Cache task_vars to speed up IncludedFile.process_include_results (#39026) --- lib/ansible/playbook/included_file.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index 55686199ac..2e3f822533 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -54,6 +54,7 @@ class IncludedFile: @staticmethod def process_include_results(results, iterator, loader, variable_manager): included_files = [] + task_vars_cache = {} for res in results: @@ -73,7 +74,11 @@ class IncludedFile: if 'skipped' in include_result and include_result['skipped'] or 'failed' in include_result and include_result['failed']: continue - task_vars = variable_manager.get_vars(play=iterator._play, host=original_host, task=original_task) + cache_key = (iterator._play, original_host, original_task) + try: + task_vars = task_vars_cache[cache_key] + except KeyError: + task_vars = task_vars_cache[cache_key] = variable_manager.get_vars(play=iterator._play, host=original_host, task=original_task) templar = Templar(loader=loader, variables=task_vars) include_variables = include_result.get('include_variables', dict())