Allow meta tasks to use tags (#67508)

* Support tags for explicit meta tasks

Add --list-tasks tests for meta tags

Add breaking_changes changelog fragment and porting guide
This commit is contained in:
Sloane Hertel 2020-08-21 11:08:49 -04:00 committed by GitHub
parent 59b80b9146
commit 1425e3597b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 7 deletions

View file

@ -0,0 +1,2 @@
breaking_changes:
- The ``meta`` module now supports tags for user-defined tasks. Internal ``meta`` tasks continue to always run. (https://github.com/ansible/ansible/issues/64558)

View file

@ -39,6 +39,7 @@ Modules
======= =======
* The ``apt_key`` module has explicitly defined ``file`` as mutually exclusive with ``data``, ``keyserver`` and ``url``. They cannot be used together anymore. * The ``apt_key`` module has explicitly defined ``file`` as mutually exclusive with ``data``, ``keyserver`` and ``url``. They cannot be used together anymore.
* The ``meta`` module now supports tags for user-defined tasks. Set the task's tags to 'always' to maintain the previous behavior. Internal ``meta`` tasks continue to always run.
Modules removed Modules removed

View file

@ -162,7 +162,7 @@ class PlaybookCLI(CLI):
if isinstance(task, Block): if isinstance(task, Block):
taskmsg += _process_block(task) taskmsg += _process_block(task)
else: else:
if task.action == 'meta': if task.action == 'meta' and task.implicit:
continue continue
all_tags.update(task.tags) all_tags.update(task.tags)

View file

@ -40,7 +40,6 @@ notes:
- C(clear_facts) will remove the persistent facts from M(ansible.builtin.set_fact) using C(cacheable=True), - C(clear_facts) will remove the persistent facts from M(ansible.builtin.set_fact) using C(cacheable=True),
but not the current host variable it creates for the current run. but not the current host variable it creates for the current run.
- Looping on meta tasks is not supported. - Looping on meta tasks is not supported.
- Skipping C(meta) tasks using tags is not supported.
- This module is also supported for Windows targets. - This module is also supported for Windows targets.
seealso: seealso:
- module: ansible.builtin.assert - module: ansible.builtin.assert

View file

@ -374,7 +374,7 @@ class Block(Base, Conditional, CollectionSearch, Taggable):
filtered_block = evaluate_block(task) filtered_block = evaluate_block(task)
if filtered_block.has_tasks(): if filtered_block.has_tasks():
tmp_list.append(filtered_block) tmp_list.append(filtered_block)
elif (task.action == 'meta' or elif ((task.action == 'meta' and task.implicit) or
(task.action == 'include' and task.evaluate_tags([], self._play.skip_tags, all_vars=all_vars)) 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)): task.evaluate_tags(self._play.only_tags, self._play.skip_tags, all_vars=all_vars)):
tmp_list.append(task) tmp_list.append(task)

View file

@ -14,7 +14,7 @@ export LC_ALL=en_US.UTF-8
# Run everything by default # Run everything by default
[ "$("${COMMAND[@]}" | grep -F Task_with | xargs)" = \ [ "$("${COMMAND[@]}" | grep -F Task_with | xargs)" = \
"Task_with_tag TAGS: [tag] Task_with_always_tag TAGS: [always] Task_with_unicode_tag TAGS: [くらとみ] Task_with_list_of_tags TAGS: [café, press] Task_without_tag TAGS: [] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3]" ] "Task_with_tag TAGS: [tag] Task_with_always_tag TAGS: [always] Task_with_unicode_tag TAGS: [くらとみ] Task_with_list_of_tags TAGS: [café, press] Task_without_tag TAGS: [] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3] Task_with_meta_tags TAGS: [meta_tag]" ]
# Run the exact tags, and always # Run the exact tags, and always
[ "$("${COMMAND[@]}" --tags tag | grep -F Task_with | xargs)" = \ [ "$("${COMMAND[@]}" --tags tag | grep -F Task_with | xargs)" = \
@ -22,11 +22,15 @@ export LC_ALL=en_US.UTF-8
# Skip one tag # Skip one tag
[ "$("${COMMAND[@]}" --skip-tags tag | grep -F Task_with | xargs)" = \ [ "$("${COMMAND[@]}" --skip-tags tag | grep -F Task_with | xargs)" = \
"Task_with_always_tag TAGS: [always] Task_with_unicode_tag TAGS: [くらとみ] Task_with_list_of_tags TAGS: [café, press] Task_without_tag TAGS: [] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3]" ] "Task_with_always_tag TAGS: [always] Task_with_unicode_tag TAGS: [くらとみ] Task_with_list_of_tags TAGS: [café, press] Task_without_tag TAGS: [] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3] Task_with_meta_tags TAGS: [meta_tag]" ]
# Skip a unicode tag # Skip a unicode tag
[ "$("${COMMAND[@]}" --skip-tags 'くらとみ' | grep -F Task_with | xargs)" = \ [ "$("${COMMAND[@]}" --skip-tags 'くらとみ' | grep -F Task_with | xargs)" = \
"Task_with_tag TAGS: [tag] Task_with_always_tag TAGS: [always] Task_with_list_of_tags TAGS: [café, press] Task_without_tag TAGS: [] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3]" ] "Task_with_tag TAGS: [tag] Task_with_always_tag TAGS: [always] Task_with_list_of_tags TAGS: [café, press] Task_without_tag TAGS: [] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3] Task_with_meta_tags TAGS: [meta_tag]" ]
# Skip a meta task tag
[ "$("${COMMAND[@]}" --skip-tags meta_tag | grep -F Task_with | xargs)" = \
"Task_with_tag TAGS: [tag] Task_with_always_tag TAGS: [always] Task_with_unicode_tag TAGS: [くらとみ] Task_with_list_of_tags TAGS: [café, press] Task_without_tag TAGS: [] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3]" ]
# Run just a unicode tag and always # Run just a unicode tag and always
[ "$("${COMMAND[@]}" --tags 'くらとみ' | grep -F Task_with | xargs)" = \ [ "$("${COMMAND[@]}" --tags 'くらとみ' | grep -F Task_with | xargs)" = \
@ -48,9 +52,13 @@ export LC_ALL=en_US.UTF-8
[ "$("${COMMAND[@]}" --tags tag3 | grep -F Task_with | xargs)" = \ [ "$("${COMMAND[@]}" --tags tag3 | grep -F Task_with | xargs)" = \
"Task_with_always_tag TAGS: [always] Task_with_templated_tags TAGS: [tag3]" ] "Task_with_always_tag TAGS: [always] Task_with_templated_tags TAGS: [tag3]" ]
# Run meta tags
[ "$("${COMMAND[@]}" --tags meta_tag | grep -F Task_with | xargs)" = \
"Task_with_always_tag TAGS: [always] Task_with_meta_tags TAGS: [meta_tag]" ]
# Run tagged # Run tagged
[ "$("${COMMAND[@]}" --tags tagged | grep -F Task_with | xargs)" = \ [ "$("${COMMAND[@]}" --tags tagged | grep -F Task_with | xargs)" = \
"Task_with_tag TAGS: [tag] Task_with_always_tag TAGS: [always] Task_with_unicode_tag TAGS: [くらとみ] Task_with_list_of_tags TAGS: [café, press] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3]" ] "Task_with_tag TAGS: [tag] Task_with_always_tag TAGS: [always] Task_with_unicode_tag TAGS: [くらとみ] Task_with_list_of_tags TAGS: [café, press] Task_with_csv_tags TAGS: [tag1, tag2] Task_with_templated_tags TAGS: [tag3] Task_with_meta_tags TAGS: [meta_tag]" ]
# Run untagged # Run untagged
[ "$("${COMMAND[@]}" --tags untagged | grep -F Task_with | xargs)" = \ [ "$("${COMMAND[@]}" --tags untagged | grep -F Task_with | xargs)" = \

View file

@ -31,3 +31,6 @@
- name: Task_with_templated_tags - name: Task_with_templated_tags
debug: msg=templated debug: msg=templated
tags: "{{ the_tags }}" tags: "{{ the_tags }}"
- name: Task_with_meta_tags
meta: reset_connection
tags: meta_tag