diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2020-06-17 20:49:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-17 11:49:32 -0700 |
commit | 2cba0dc75c994afa2bc96ada3595f0bdc79b16d8 (patch) | |
tree | 1d663771bdaa914e37609e1b42a2053759723bc1 | |
parent | 94df27233f707b0de69889a52c2ec05833e4d514 (diff) | |
download | ansible-2cba0dc75c994afa2bc96ada3595f0bdc79b16d8.tar.gz |
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)
-rw-r--r-- | changelogs/fragments/purge-empty-block.yml | 2 | ||||
-rw-r--r-- | lib/ansible/playbook/block.py | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/changelogs/fragments/purge-empty-block.yml b/changelogs/fragments/purge-empty-block.yml new file mode 100644 index 0000000000..448f6b73d9 --- /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 2bd7bd8a41..4324a77ef5 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)): |