mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Allow tags to be templated from a variable (#49833)
* Allow tags to be templated from a variable. Fixes #49825 * Restore _load_tags to ensure we do csv tag splitting * Add tests for csv tags and templated tags * evaluate_tags doesn't need to accept strings, because _load_tags handles this
This commit is contained in:
@@ -14,7 +14,7 @@ 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_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 the exact tags, and always
|
||||
[ "$("${COMMAND[@]}" --tags tag | grep -F Task_with | xargs)" = \
|
||||
@@ -22,11 +22,11 @@ export LC_ALL=en_US.UTF-8
|
||||
|
||||
# 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_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]" ]
|
||||
|
||||
# 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_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]" ]
|
||||
|
||||
# Run just a unicode tag and always
|
||||
[ "$("${COMMAND[@]}" --tags 'くらとみ' | grep -F Task_with | xargs)" = \
|
||||
@@ -39,3 +39,11 @@ export LC_ALL=en_US.UTF-8
|
||||
# Run tag with never
|
||||
[ "$("${COMMAND[@]}" --tags donever | grep -F Task_with | xargs)" = \
|
||||
"Task_with_always_tag TAGS: [always] Task_with_never_tag TAGS: [donever, never]" ]
|
||||
|
||||
# Run csv tags
|
||||
[ "$("${COMMAND[@]}" --tags tag1 | grep -F Task_with | xargs)" = \
|
||||
"Task_with_always_tag TAGS: [always] Task_with_csv_tags TAGS: [tag1, tag2]" ]
|
||||
|
||||
# Run templated tags
|
||||
[ "$("${COMMAND[@]}" --tags tag3 | grep -F Task_with | xargs)" = \
|
||||
"Task_with_always_tag TAGS: [always] Task_with_templated_tags TAGS: [tag3]" ]
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
hosts: localhost
|
||||
gather_facts: False
|
||||
connection: local
|
||||
vars:
|
||||
the_tags:
|
||||
- tag3
|
||||
tasks:
|
||||
- name: Task_with_tag
|
||||
debug: msg=
|
||||
@@ -23,3 +26,9 @@
|
||||
- name: Task_with_never_tag
|
||||
debug: msg=NEVER
|
||||
tags: ['never', 'donever']
|
||||
- name: Task_with_csv_tags
|
||||
debug: msg=csv
|
||||
tags: tag1,tag2
|
||||
- name: Task_with_templated_tags
|
||||
debug: msg=templated
|
||||
tags: "{{ the_tags }}"
|
||||
|
||||
@@ -98,8 +98,5 @@ class TestTaggable(unittest.TestCase):
|
||||
def test_evaluate_tags_accepts_lists(self):
|
||||
self.assert_evaluate_equal(True, ['tag1', 'tag2'], ['tag2'], [])
|
||||
|
||||
def test_evaluate_tags_accepts_strings(self):
|
||||
self.assert_evaluate_equal(True, 'tag1,tag2', ['tag2'], [])
|
||||
|
||||
def test_evaluate_tags_with_repeated_tags(self):
|
||||
self.assert_evaluate_equal(False, ['tag', 'tag'], [], ['tag'])
|
||||
|
||||
Reference in New Issue
Block a user