From 71402abf2162f951000e1ce8e5210f39a602bf6d Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 1 Mar 2016 15:11:04 -0500 Subject: [PATCH] only do squash when 'squashable field' present --- lib/ansible/executor/task_executor.py | 47 ++++++++++++++------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index b59295b0ed7..a0881cc222b 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -279,29 +279,30 @@ class TaskExecutor: # This gets the information to check whether the name field # contains a template that we can squash for template_no_item = template_with_item = None - if templar._contains_vars(name): - variables['item'] = '\0$' - template_no_item = templar.template(name, variables, cache=False) - variables['item'] = '\0@' - template_with_item = templar.template(name, variables, cache=False) - del variables['item'] - - # Check if the user is doing some operation that doesn't take - # name/pkg or the name/pkg field doesn't have any variables - # and thus the items can't be squashed - if name and (template_no_item != template_with_item): - for item in items: - variables['item'] = item - if self._task.evaluate_conditional(templar, variables): - new_item = templar.template(name, cache=False) - final_items.append(new_item) - self._task.args['name'] = final_items - # Wrap this in a list so that the calling function loop - # executes exactly once - return [final_items] - else: - # Restore the name parameter - self._task.args['name'] = name + if name: + if templar._contains_vars(name): + variables['item'] = '\0$' + template_no_item = templar.template(name, variables, cache=False) + variables['item'] = '\0@' + template_with_item = templar.template(name, variables, cache=False) + del variables['item'] + + # Check if the user is doing some operation that doesn't take + # name/pkg or the name/pkg field doesn't have any variables + # and thus the items can't be squashed + if template_no_item != template_with_item: + for item in items: + variables['item'] = item + if self._task.evaluate_conditional(templar, variables): + new_item = templar.template(name, cache=False) + final_items.append(new_item) + self._task.args['name'] = final_items + # Wrap this in a list so that the calling function loop + # executes exactly once + return [final_items] + else: + # Restore the name parameter + self._task.args['name'] = name #elif: # Right now we only optimize single entries. In the future we # could optimize more types: