| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
set -eux |
| 4 |
|
| 5 |
export ANSIBLE_FORCE_HANDLERS |
| 6 |
|
| 7 |
ANSIBLE_FORCE_HANDLERS=false |
| 8 |
|
| 9 |
# simple handler test |
| 10 |
ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario1 |
| 11 |
|
| 12 |
# simple from_handlers test |
| 13 |
ansible-playbook from_handlers.yml -i inventory.handlers -v "$@" --tags scenario1 |
| 14 |
|
| 15 |
ansible-playbook test_listening_handlers.yml -i inventory.handlers -v "$@" |
| 16 |
|
| 17 |
[ "$(ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario2 -l A \ |
| 18 |
| grep -E -o 'RUNNING HANDLER \[test_handlers : .*]')" = "RUNNING HANDLER [test_handlers : test handler]" ] |
| 19 |
|
| 20 |
# Test forcing handlers using the linear and free strategy |
| 21 |
for strategy in linear free; do |
| 22 |
|
| 23 |
export ANSIBLE_STRATEGY=$strategy |
| 24 |
|
| 25 |
# Not forcing, should only run on successful host |
| 26 |
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \ |
| 27 |
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ] |
| 28 |
|
| 29 |
# Forcing from command line |
| 30 |
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers \ |
| 31 |
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ] |
| 32 |
|
| 33 |
# Forcing from command line, should only run later tasks on unfailed hosts |
| 34 |
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers \ |
| 35 |
| grep -E -o CALLED_TASK_. | sort | uniq | xargs)" = "CALLED_TASK_B CALLED_TASK_D CALLED_TASK_E" ] |
| 36 |
|
| 37 |
# Forcing from command line, should call handlers even if all hosts fail |
| 38 |
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers -e fail_all=yes \ |
| 39 |
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ] |
| 40 |
|
| 41 |
# Forcing from ansible.cfg |
| 42 |
[ "$(ANSIBLE_FORCE_HANDLERS=true ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \ |
| 43 |
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ] |
| 44 |
|
| 45 |
# Forcing true in play |
| 46 |
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_true_in_play \ |
| 47 |
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ] |
| 48 |
|
| 49 |
# Forcing false in play, which overrides command line |
| 50 |
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_false_in_play --force-handlers \ |
| 51 |
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ] |
| 52 |
|
| 53 |
# https://github.com/ansible/ansible/pull/80898 |
| 54 |
[ "$(ansible-playbook 80880.yml -i inventory.handlers -vv "$@" 2>&1)" ] |
| 55 |
|
| 56 |
unset ANSIBLE_STRATEGY |
| 57 |
|
| 58 |
done |
| 59 |
|
| 60 |
[ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags playbook_include_handlers \ |
| 61 |
| grep -E -o 'RUNNING HANDLER \[.*]')" = "RUNNING HANDLER [test handler]" ] |
| 62 |
|
| 63 |
[ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags role_include_handlers \ |
| 64 |
| grep -E -o 'RUNNING HANDLER \[test_handlers_include : .*]')" = "RUNNING HANDLER [test_handlers_include : test handler]" ] |
| 65 |
|
| 66 |
[ "$(ansible-playbook test_handlers_include_role.yml -i ../../inventory -v "$@" \ |
| 67 |
| grep -E -o 'RUNNING HANDLER \[test_handlers_include_role : .*]')" = "RUNNING HANDLER [test_handlers_include_role : test handler]" ] |
| 68 |
|
| 69 |
# Notify handler listen |
| 70 |
ansible-playbook test_handlers_listen.yml -i inventory.handlers -v "$@" |
| 71 |
|
| 72 |
# https://github.com/ansible/ansible/issues/82363 |
| 73 |
ansible-playbook test_multiple_handlers_with_recursive_notification.yml -i inventory.handlers -v "$@" |
| 74 |
|
| 75 |
# Notify inexistent handlers results in error |
| 76 |
set +e |
| 77 |
result="$(ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers "$@" 2>&1)" |
| 78 |
set -e |
| 79 |
grep -q "The requested handler 'notify_inexistent_handler' was not found in either the main handlers list nor in the listening handlers list" <<< "$result" |
| 80 |
|
| 81 |
# Notify inexistent handlers without errors when ANSIBLE_ERROR_ON_MISSING_HANDLER=false |
| 82 |
ANSIBLE_ERROR_ON_MISSING_HANDLER=false ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers -v "$@" |
| 83 |
|
| 84 |
ANSIBLE_ERROR_ON_MISSING_HANDLER=false ansible-playbook test_templating_in_handlers.yml -v "$@" |
| 85 |
|
| 86 |
# https://github.com/ansible/ansible/issues/36649 |
| 87 |
output_dir=/tmp |
| 88 |
set +e |
| 89 |
result="$(ansible-playbook test_handlers_any_errors_fatal.yml -e output_dir=$output_dir -i inventory.handlers -v "$@" 2>&1)" |
| 90 |
set -e |
| 91 |
[ ! -f $output_dir/should_not_exist_B ] || (rm -f $output_dir/should_not_exist_B && exit 1) |
| 92 |
|
| 93 |
# https://github.com/ansible/ansible/issues/47287 |
| 94 |
[ "$(ansible-playbook test_handlers_including_task.yml -i ../../inventory -v "$@" | grep -E -o 'failed=[0-9]+')" = "failed=0" ] |
| 95 |
|
| 96 |
# https://github.com/ansible/ansible/issues/71222 |
| 97 |
ansible-playbook test_role_handlers_including_tasks.yml -i ../../inventory -v "$@" |
| 98 |
|
| 99 |
# https://github.com/ansible/ansible/issues/27237 |
| 100 |
set +e |
| 101 |
result="$(ansible-playbook test_handlers_template_run_once.yml -i inventory.handlers "$@" 2>&1)" |
| 102 |
set -e |
| 103 |
grep -q "handler A" <<< "$result" |
| 104 |
grep -q "handler B" <<< "$result" |
| 105 |
|
| 106 |
# Test an undefined variable in another handler name isn't a failure |
| 107 |
ansible-playbook 58841.yml "$@" --tags lazy_evaluation 2>&1 | tee out.txt ; cat out.txt |
| 108 |
grep out.txt -e "\[WARNING\]: Handler 'handler name with {{ test_var }}' is unusable" |
| 109 |
[ "$(grep out.txt -ce 'handler ran')" = "1" ] |
| 110 |
[ "$(grep out.txt -ce 'handler with var ran')" = "0" ] |
| 111 |
|
| 112 |
# Test templating a handler name with a defined variable |
| 113 |
ansible-playbook 58841.yml "$@" --tags evaluation_time -e test_var=myvar | tee out.txt ; cat out.txt |
| 114 |
[ "$(grep out.txt -ce 'handler ran')" = "0" ] |
| 115 |
[ "$(grep out.txt -ce 'handler with var ran')" = "1" ] |
| 116 |
|
| 117 |
# Test the handler is not found when the variable is undefined |
| 118 |
ansible-playbook 58841.yml "$@" --tags evaluation_time 2>&1 | tee out.txt ; cat out.txt |
| 119 |
grep out.txt -e "The requested handler 'handler name with myvar' was not found" |
| 120 |
grep out.txt -e "\[WARNING\]: Handler 'handler name with {{ test_var }}' is unusable" |
| 121 |
[ "$(grep out.txt -ce 'handler ran')" = "0" ] |
| 122 |
[ "$(grep out.txt -ce 'handler with var ran')" = "0" ] |
| 123 |
|
| 124 |
# Test include_role and import_role cannot be used as handlers |
| 125 |
ansible-playbook test_role_as_handler.yml "$@" 2>&1 | tee out.txt |
| 126 |
grep out.txt -e "Using 'include_role' as a handler is not supported." |
| 127 |
|
| 128 |
# Test notifying a handler from within include_tasks does not work anymore |
| 129 |
ansible-playbook test_notify_included.yml "$@" 2>&1 | tee out.txt |
| 130 |
[ "$(grep out.txt -ce 'I was included')" = "1" ] |
| 131 |
grep out.txt -e "The requested handler 'handler_from_include' was not found in either the main handlers list nor in the listening handlers list" |
| 132 |
|
| 133 |
ansible-playbook test_handlers_meta.yml -i inventory.handlers -vv "$@" | tee out.txt |
| 134 |
[ "$(grep out.txt -ce 'RUNNING HANDLER \[noop_handler\]')" = "1" ] |
| 135 |
[ "$(grep out.txt -ce 'META: noop')" = "1" ] |
| 136 |
|
| 137 |
# https://github.com/ansible/ansible/issues/46447 |
| 138 |
test "$(ansible-playbook 46447.yml -i inventory.handlers "$@" 2>&1 | grep -c 'SHOULD NOT GET HERE')" = "0" |
| 139 |
|
| 140 |
# https://github.com/ansible/ansible/issues/52561 |
| 141 |
ansible-playbook 52561.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 142 |
[ "$(grep out.txt -ce 'handler1 ran')" = "1" ] |
| 143 |
|
| 144 |
# Test flush_handlers meta task does not imply any_errors_fatal |
| 145 |
ansible-playbook 54991.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 146 |
[ "$(grep out.txt -ce 'handler ran')" = "4" ] |
| 147 |
|
| 148 |
ansible-playbook order.yml -i inventory.handlers "$@" 2>&1 |
| 149 |
set +e |
| 150 |
ansible-playbook order.yml --force-handlers -e test_force_handlers=true -i inventory.handlers "$@" 2>&1 |
| 151 |
set -e |
| 152 |
|
| 153 |
ansible-playbook include_handlers_fail_force.yml --force-handlers -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 154 |
[ "$(grep out.txt -ce 'included handler ran')" = "1" ] |
| 155 |
|
| 156 |
ansible-playbook test_flush_handlers_as_handler.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 157 |
grep out.txt -e "flush_handlers cannot be used as a handler" |
| 158 |
|
| 159 |
ansible-playbook test_skip_flush.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 160 |
[ "$(grep out.txt -ce 'handler ran')" = "0" ] |
| 161 |
|
| 162 |
ansible-playbook test_flush_in_rescue_always.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 163 |
[ "$(grep out.txt -ce 'handler ran in rescue')" = "1" ] |
| 164 |
[ "$(grep out.txt -ce 'handler ran in always')" = "2" ] |
| 165 |
[ "$(grep out.txt -ce 'lockstep works')" = "2" ] |
| 166 |
|
| 167 |
ansible-playbook test_handlers_infinite_loop.yml -i inventory.handlers "$@" 2>&1 |
| 168 |
|
| 169 |
ansible-playbook test_flush_handlers_rescue_always.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 170 |
[ "$(grep out.txt -ce 'rescue ran')" = "1" ] |
| 171 |
[ "$(grep out.txt -ce 'always ran')" = "2" ] |
| 172 |
[ "$(grep out.txt -ce 'should run for both hosts')" = "2" ] |
| 173 |
|
| 174 |
ansible-playbook test_fqcn_meta_flush_handlers.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 175 |
grep out.txt -e "handler ran" |
| 176 |
grep out.txt -e "after flush" |
| 177 |
|
| 178 |
ansible-playbook 79776.yml -i inventory.handlers "$@" |
| 179 |
|
| 180 |
ansible-playbook test_block_as_handler.yml "$@" 2>&1 | tee out.txt |
| 181 |
grep out.txt -e "Using a block as a handler is not supported." |
| 182 |
|
| 183 |
ansible-playbook test_block_as_handler-include.yml "$@" 2>&1 | tee out.txt |
| 184 |
grep out.txt -e "Using a block as a handler is not supported." |
| 185 |
|
| 186 |
ansible-playbook test_block_as_handler-import.yml "$@" 2>&1 | tee out.txt |
| 187 |
grep out.txt -e "Using a block as a handler is not supported." |
| 188 |
|
| 189 |
ansible-playbook test_include_role_handler_once.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 190 |
[ "$(grep out.txt -ce 'handler ran')" = "1" ] |
| 191 |
|
| 192 |
ansible-playbook test_listen_role_dedup.yml "$@" 2>&1 | tee out.txt |
| 193 |
[ "$(grep out.txt -ce 'a handler from a role')" = "1" ] |
| 194 |
|
| 195 |
ansible localhost -m include_role -a "name=r1-dep_chain-vars" "$@" |
| 196 |
|
| 197 |
ansible-playbook test_include_tasks_in_include_role.yml "$@" 2>&1 | tee out.txt |
| 198 |
[ "$(grep out.txt -ce 'handler ran')" = "1" ] |
| 199 |
|
| 200 |
ansible-playbook test_run_once.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 201 |
[ "$(grep out.txt -ce 'handler ran once')" = "1" ] |
| 202 |
|
| 203 |
ansible-playbook force_handlers_blocks_81533-1.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 204 |
[ "$(grep out.txt -ce 'task1')" = "1" ] |
| 205 |
[ "$(grep out.txt -ce 'task2')" = "1" ] |
| 206 |
[ "$(grep out.txt -ce 'hosts_left')" = "1" ] |
| 207 |
|
| 208 |
ansible-playbook force_handlers_blocks_81533-2.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 209 |
[ "$(grep out.txt -ce 'hosts_left')" = "1" ] |
| 210 |
|
| 211 |
ansible-playbook nested_flush_handlers_failure_force.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 212 |
[ "$(grep out.txt -ce '"flush_handlers_rescued"')" = "1" ] |
| 213 |
[ "$(grep out.txt -ce '"flush_handlers_always"')" = "2" ] |
| 214 |
|
| 215 |
ansible-playbook 82241.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 216 |
[ "$(grep out.txt -ce 'included_task_from_tasks_dir')" = "1" ] |
| 217 |
|
| 218 |
ansible-playbook handlers_lockstep_82307.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 219 |
[ "$(grep out.txt -ce 'TASK \[handler2\]')" = "0" ] |
| 220 |
|
| 221 |
ansible-playbook handlers_lockstep_83019.yml -i inventory.handlers "$@" 2>&1 | tee out.txt |
| 222 |
[ "$(grep out.txt -ce 'TASK \[handler1\]')" = "0" ] |
| 223 |
|
| 224 |
ansible-playbook handler_notify_earlier_handler.yml "$@" 2>&1 | tee out.txt |
| 225 |
[ "$(grep out.txt -ce 'h1_ran')" = "1" ] |
| 226 |
[ "$(grep out.txt -ce 'h2_ran')" = "1" ] |
| 227 |
[ "$(grep out.txt -ce 'h3_ran')" = "1" ] |
| 228 |
[ "$(grep out.txt -ce 'h4_ran')" = "1" ] |
| 229 |
|
| 230 |
ANSIBLE_DEBUG=1 ansible-playbook tagged_play.yml --skip-tags the_whole_play "$@" 2>&1 | tee out.txt |
| 231 |
[ "$(grep out.txt -ce 'META: triggered running handlers')" = "0" ] |
| 232 |
[ "$(grep out.txt -ce 'No handler notifications for')" = "0" ] |
| 233 |
[ "$(grep out.txt -ce 'handler_ran')" = "0" ] |
| 234 |
[ "$(grep out.txt -ce 'handler1_ran')" = "0" ] |
| 235 |
|
| 236 |
ansible-playbook rescue_flush_handlers.yml "$@" |
| 237 |
|
| 238 |
ANSIBLE_DEBUG=1 ansible-playbook tagged_play.yml --tags task_tag "$@" 2>&1 | tee out.txt |
| 239 |
[ "$(grep out.txt -ce 'META: triggered running handlers')" = "1" ] |
| 240 |
[ "$(grep out.txt -ce 'handler_ran')" = "0" ] |
| 241 |
[ "$(grep out.txt -ce 'handler1_ran')" = "1" ] |