Skip to content

Commit

Permalink
Support tags for explicit meta tasks
Browse files Browse the repository at this point in the history
Add --list-tasks tests for meta tags

changelog

ci_complete
  • Loading branch information
s-hertel committed Aug 19, 2020
1 parent 2675768 commit 38315d5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/67508-meta-task-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- User-defined ``meta`` tasks now support tags. Internally-created ``meta`` tasks continue to always run regardless of tags. (https://github.com/ansible/ansible/issues/64558)
2 changes: 1 addition & 1 deletion lib/ansible/cli/playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _process_block(b):
if isinstance(task, Block):
taskmsg += _process_block(task)
else:
if task.action == 'meta':
if task.action == 'meta' and task.implicit is True:
continue

all_tags.update(task.tags)
Expand Down
1 change: 0 additions & 1 deletion lib/ansible/modules/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
- 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.
- Looping on meta tasks is not supported.
- Skipping C(meta) tasks using tags is not supported.
- This module is also supported for Windows targets.
seealso:
- module: ansible.builtin.assert
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/playbook/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def evaluate_and_append_task(target):
filtered_block = evaluate_block(task)
if filtered_block.has_tasks():
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.evaluate_tags(self._play.only_tags, self._play.skip_tags, all_vars=all_vars)):
tmp_list.append(task)
Expand Down
16 changes: 12 additions & 4 deletions test/integration/targets/tags/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ export LC_ALL=en_US.UTF-8

# Run everything by default
[ "$("${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
[ "$("${COMMAND[@]}" --tags tag | grep -F Task_with | xargs)" = \
"Task_with_tag TAGS: [tag] Task_with_always_tag TAGS: [always]" ]

# Skip one tag
[ "$("${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
[ "$("${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
[ "$("${COMMAND[@]}" --tags 'くらとみ' | grep -F Task_with | xargs)" = \
Expand All @@ -48,9 +52,13 @@ export LC_ALL=en_US.UTF-8
[ "$("${COMMAND[@]}" --tags tag3 | grep -F Task_with | xargs)" = \
"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
[ "$("${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
[ "$("${COMMAND[@]}" --tags untagged | grep -F Task_with | xargs)" = \
Expand Down
3 changes: 3 additions & 0 deletions test/integration/targets/tags/test_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
- name: Task_with_templated_tags
debug: msg=templated
tags: "{{ the_tags }}"
- name: Task_with_meta_tags
meta: reset_connection
tags: meta_tag

0 comments on commit 38315d5

Please sign in to comment.