diff options
Diffstat (limited to '')
-rw-r--r-- | test/integration/targets/tags/aliases | 2 | ||||
-rw-r--r-- | test/integration/targets/tags/ansible_run_tags.yml | 49 | ||||
-rwxr-xr-x | test/integration/targets/tags/runme.sh | 75 | ||||
-rw-r--r-- | test/integration/targets/tags/test_tags.yml | 36 |
4 files changed, 162 insertions, 0 deletions
diff --git a/test/integration/targets/tags/aliases b/test/integration/targets/tags/aliases new file mode 100644 index 0000000..1d28bdb --- /dev/null +++ b/test/integration/targets/tags/aliases @@ -0,0 +1,2 @@ +shippable/posix/group5 +context/controller diff --git a/test/integration/targets/tags/ansible_run_tags.yml b/test/integration/targets/tags/ansible_run_tags.yml new file mode 100644 index 0000000..0e965ad --- /dev/null +++ b/test/integration/targets/tags/ansible_run_tags.yml @@ -0,0 +1,49 @@ +--- +- name: verify ansible_run_tags work as expected + hosts: testhost + gather_facts: False + tasks: + - debug: + var: ansible_run_tags + tags: + - always + + - debug: + var: expect + tags: + - always + + - assert: + that: + - ansible_run_tags == ['all'] + when: expect == 'all' + tags: + - always + + - assert: + that: + - ansible_run_tags|sort == ['tag1', 'tag3'] + when: expect == 'list' + tags: + - always + + - assert: + that: + - ansible_run_tags == ['untagged'] + when: expect == 'untagged' + tags: + - always + + - assert: + that: + - ansible_run_tags|sort == ['tag3', 'untagged'] + when: expect == 'untagged_list' + tags: + - always + + - assert: + that: + - ansible_run_tags == ['tagged'] + when: expect == 'tagged' + tags: + - always diff --git a/test/integration/targets/tags/runme.sh b/test/integration/targets/tags/runme.sh new file mode 100755 index 0000000..9da0b30 --- /dev/null +++ b/test/integration/targets/tags/runme.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +set -eux -o pipefail + +# Run these using en_US.UTF-8 because list-tasks is a user output function and so it tailors its output to the +# user's locale. For unicode tags, this means replacing non-ascii chars with "?" + +COMMAND=(ansible-playbook -i ../../inventory test_tags.yml -v --list-tasks) + +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_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_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_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)" = \ +"Task_with_always_tag TAGS: [always] Task_with_unicode_tag TAGS: [くらとみ]" ] + +# Run a tag from a list of tags and always +[ "$("${COMMAND[@]}" --tags café | grep -F Task_with | xargs)" = \ +"Task_with_always_tag TAGS: [always] Task_with_list_of_tags TAGS: [café, press]" ] + +# 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]" ] + +# 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_meta_tags TAGS: [meta_tag]" ] + +# Run untagged +[ "$("${COMMAND[@]}" --tags untagged | grep -F Task_with | xargs)" = \ +"Task_with_always_tag TAGS: [always] Task_without_tag TAGS: []" ] + +# Skip 'always' +[ "$("${COMMAND[@]}" --tags untagged --skip-tags always | grep -F Task_with | xargs)" = \ +"Task_without_tag TAGS: []" ] + +# Test ansible_run_tags +ansible-playbook -i ../../inventory ansible_run_tags.yml -e expect=all "$@" +ansible-playbook -i ../../inventory ansible_run_tags.yml -e expect=all --tags all "$@" +ansible-playbook -i ../../inventory ansible_run_tags.yml -e expect=list --tags tag1,tag3 "$@" +ansible-playbook -i ../../inventory ansible_run_tags.yml -e expect=list --tags tag1 --tags tag3 "$@" +ansible-playbook -i ../../inventory ansible_run_tags.yml -e expect=untagged --tags untagged "$@" +ansible-playbook -i ../../inventory ansible_run_tags.yml -e expect=untagged_list --tags untagged,tag3 "$@" +ansible-playbook -i ../../inventory ansible_run_tags.yml -e expect=tagged --tags tagged "$@" diff --git a/test/integration/targets/tags/test_tags.yml b/test/integration/targets/tags/test_tags.yml new file mode 100644 index 0000000..f0f9a72 --- /dev/null +++ b/test/integration/targets/tags/test_tags.yml @@ -0,0 +1,36 @@ +--- +- name: verify tags work as expected + hosts: testhost + gather_facts: False + vars: + the_tags: + - tag3 + tasks: + - name: Task_with_tag + debug: msg= + tags: tag + - name: Task_with_always_tag + debug: msg= + tags: always + - name: Task_with_unicode_tag + debug: msg= + tags: くらとみ + - name: Task_with_list_of_tags + debug: msg= + tags: + - café + - press + - name: Task_without_tag + debug: msg= + - 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 }}" + - name: Task_with_meta_tags + meta: reset_connection + tags: meta_tag |