From 2cba0dc75c994afa2bc96ada3595f0bdc79b16d8 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 17 Jun 2020 20:49:32 +0200 Subject: [PATCH] Do not keep empty blocks after tag filtering (#69987) (#69999) This prevents PlayIterator having to go through empty blocks that were created in filter_tagged_tasks. This should be a performance improvement for playbooks that mostly skip tasks with tags. ci_complete (cherry picked from commit ac2046637510eed8e31ca0c88aebce3279f38070) --- changelogs/fragments/purge-empty-block.yml | 2 ++ lib/ansible/playbook/block.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/purge-empty-block.yml diff --git a/changelogs/fragments/purge-empty-block.yml b/changelogs/fragments/purge-empty-block.yml new file mode 100644 index 00000000000..448f6b73d95 --- /dev/null +++ b/changelogs/fragments/purge-empty-block.yml @@ -0,0 +1,2 @@ +bugfixes: + - Do not keep empty blocks in PlayIterator after skipping tasks with tags. diff --git a/lib/ansible/playbook/block.py b/lib/ansible/playbook/block.py index 2bd7bd8a41e..4324a77ef54 100644 --- a/lib/ansible/playbook/block.py +++ b/lib/ansible/playbook/block.py @@ -371,7 +371,9 @@ class Block(Base, Conditional, CollectionSearch, Taggable): tmp_list = [] for task in target: if isinstance(task, Block): - tmp_list.append(evaluate_block(task)) + filtered_block = evaluate_block(task) + if filtered_block.has_tasks(): + tmp_list.append(filtered_block) elif (task.action == 'meta' or (task.action == 'include' and task.evaluate_tags([], self._play.skip_tags, all_vars=all_vars)) or task.evaluate_tags(self._play.only_tags, self._play.skip_tags, all_vars=all_vars)):