[stable-2.8] Add test for meta: end_play (#59118)

- Set ansible_python_interpreter for hosts using local connection
(cherry picked from commit d17e7a91b1)

Co-authored-by: Sam Doran <sdoran@redhat.com>
This commit is contained in:
Sam Doran 2019-07-16 12:41:48 -04:00 committed by Toshio Kuratomi
parent 0d86a4dbaa
commit f837444a77
4 changed files with 31 additions and 5 deletions

View file

@ -1,3 +0,0 @@
[local]
testhost ansible_connection=local host_var_role_name=role3
testhost2 ansible_connection=local host_var_role_name=role2

View file

@ -0,0 +1,9 @@
local:
hosts:
testhost:
host_var_role_name: role3
testhost2:
host_var_role_name: role2
vars:
ansible_connection: local
ansible_python_interpreter: "{{ ansible_playbook_python }}"

View file

@ -4,7 +4,7 @@ set -eux
# test end_host meta task, with when conditional
for test_strategy in linear free; do
out="$(ansible-playbook test_end_host.yml -i inventory -e test_strategy=$test_strategy -vv "$@")"
out="$(ansible-playbook test_end_host.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")"
grep -q "META: end_host conditional evaluated to false, continuing execution for testhost" <<< "$out"
grep -q "META: ending play for testhost2" <<< "$out"
@ -14,10 +14,18 @@ done
# test end_host meta task, on all hosts
for test_strategy in linear free; do
out="$(ansible-playbook test_end_host_all.yml -i inventory -e test_strategy=$test_strategy -vv "$@")"
out="$(ansible-playbook test_end_host_all.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")"
grep -q "META: ending play for testhost" <<< "$out"
grep -q "META: ending play for testhost2" <<< "$out"
grep -qv "play not ended for testhost" <<< "$out"
grep -qv "play not ended for testhost2" <<< "$out"
done
# test end_play meta task
for test_strategy in linear free; do
out="$(ansible-playbook test_end_play.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")"
grep -q "META: ending play" <<< "$out"
grep -qv 'Failed to end using end_play' <<< "$out"
done

View file

@ -0,0 +1,12 @@
- name: Testing end_play with strategy {{ test_strategy | default('linear') }}
hosts: testhost:testhost2
gather_facts: no
strategy: "{{ test_strategy | default('linear') }}"
tasks:
- debug:
msg: "Testing end_play on host {{ inventory_hostname }}"
- meta: end_play
- fail:
msg: 'Failed to end using end_play'