| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
set -eux |
| 4 |
|
| 5 |
# test end_host meta task, with when conditional |
| 6 |
for test_strategy in linear free; do |
| 7 |
out="$(ansible-playbook test_end_host.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" |
| 8 |
|
| 9 |
grep -q "META: end_host conditional evaluated to False, continuing execution for testhost" <<< "$out" |
| 10 |
grep -q "META: ending play for testhost2" <<< "$out" |
| 11 |
grep -q 'META: end_host conditional evaluated to False, continuing execution for testhost' <<< "$out" |
| 12 |
grep -q "play not ended for testhost" <<< "$out" |
| 13 |
grep -qv "play not ended for testhost2" <<< "$out" |
| 14 |
|
| 15 |
out="$(ansible-playbook test_end_host_fqcn.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" |
| 16 |
|
| 17 |
grep -q "META: end_host conditional evaluated to False, continuing execution for testhost" <<< "$out" |
| 18 |
grep -q "META: ending play for testhost2" <<< "$out" |
| 19 |
grep -q 'META: end_host conditional evaluated to False, continuing execution for testhost' <<< "$out" |
| 20 |
grep -q "play not ended for testhost" <<< "$out" |
| 21 |
grep -qv "play not ended for testhost2" <<< "$out" |
| 22 |
done |
| 23 |
|
| 24 |
# test end_host meta task, on all hosts |
| 25 |
for test_strategy in linear free; do |
| 26 |
out="$(ansible-playbook test_end_host_all.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" |
| 27 |
|
| 28 |
grep -q "META: ending play for testhost" <<< "$out" |
| 29 |
grep -q "META: ending play for testhost2" <<< "$out" |
| 30 |
grep -qv "play not ended for testhost" <<< "$out" |
| 31 |
grep -qv "play not ended for testhost2" <<< "$out" |
| 32 |
|
| 33 |
out="$(ansible-playbook test_end_host_all_fqcn.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" |
| 34 |
|
| 35 |
grep -q "META: ending play for testhost" <<< "$out" |
| 36 |
grep -q "META: ending play for testhost2" <<< "$out" |
| 37 |
grep -qv "play not ended for testhost" <<< "$out" |
| 38 |
grep -qv "play not ended for testhost2" <<< "$out" |
| 39 |
done |
| 40 |
|
| 41 |
# test end_play meta task |
| 42 |
for test_strategy in linear free; do |
| 43 |
# $@ omitted to avoid additional verbosity, which will line-break and indent the JSON output we need to check |
| 44 |
out="$(ansible-playbook test_end_play.yml -i inventory.yml -e test_strategy=$test_strategy -vv)" |
| 45 |
|
| 46 |
grep -q "skipping:.*end_play conditional evaluated to False, continuing play" <<< "$out" |
| 47 |
grep -q "META: ending play" <<< "$out" |
| 48 |
grep -qv 'Failed to end using end_play' <<< "$out" |
| 49 |
|
| 50 |
out="$(ansible-playbook test_end_play_fqcn.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" |
| 51 |
|
| 52 |
grep -q "META: ending play" <<< "$out" |
| 53 |
grep -qv 'Failed to end using end_play' <<< "$out" |
| 54 |
|
| 55 |
out="$(ansible-playbook test_end_play_serial_one.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" |
| 56 |
|
| 57 |
[ "$(grep -c "Testing end_play on host" <<< "$out" )" -eq 1 ] |
| 58 |
grep -q "META: ending play" <<< "$out" |
| 59 |
grep -qv 'Failed to end using end_play' <<< "$out" |
| 60 |
|
| 61 |
out="$(ansible-playbook test_end_play_multiple_plays.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" |
| 62 |
|
| 63 |
grep -q "META: ending play" <<< "$out" |
| 64 |
grep -q "Play 1" <<< "$out" |
| 65 |
grep -q "Play 2" <<< "$out" |
| 66 |
grep -qv 'Failed to end using end_play' <<< "$out" |
| 67 |
done |
| 68 |
|
| 69 |
# test end_batch meta task |
| 70 |
for test_strategy in linear free; do |
| 71 |
out="$(ansible-playbook test_end_batch.yml -i inventory.yml -e test_strategy=$test_strategy -vv "$@")" |
| 72 |
|
| 73 |
[ "$(grep -c "Using end_batch" <<< "$out" )" -eq 2 ] |
| 74 |
[ "$(grep -c "META: ending batch" <<< "$out" )" -eq 2 ] |
| 75 |
grep -qv 'Failed to end_batch' <<< "$out" |
| 76 |
done |
| 77 |
|
| 78 |
# test refresh |
| 79 |
ansible-playbook -i inventory_refresh.yml refresh.yml "$@" |
| 80 |
ansible-playbook -i inventory_refresh.yml refresh_preserve_dynamic.yml "$@" |
| 81 |
|
| 82 |
# test rc when end_host in the rescue section |
| 83 |
ANSIBLE_FORCE_HANDLERS=0 ansible-playbook test_end_host_rescue_rc.yml |
| 84 |
|
| 85 |
# test end_role meta task |
| 86 |
for test_strategy in linear free; do |
| 87 |
out="$(ansible-playbook test_end_role.yml -i inventory.yml -e test_strategy=$test_strategy -e end_role_cond=1 -vv "$@")" |
| 88 |
|
| 89 |
grep -q "META: end_role conditional evaluated to False," <<< "$out" |
| 90 |
done |