2016-10-12 23:57:53 +02:00
#!/usr/bin/env bash
set -eux
2019-01-25 09:04:58 +01:00
export ANSIBLE_FORCE_HANDLERS
ANSIBLE_FORCE_HANDLERS = false
2018-12-18 17:28:24 +01:00
# simple handler test
2016-10-12 23:57:53 +02:00
ansible-playbook test_handlers.yml -i inventory.handlers -v " $@ " --tags scenario1
2018-12-18 17:28:24 +01:00
# simple from_handlers test
ansible-playbook from_handlers.yml -i inventory.handlers -v " $@ " --tags scenario1
2016-11-13 08:26:43 +01:00
ansible-playbook test_listening_handlers.yml -i inventory.handlers -v " $@ "
2016-10-12 23:57:53 +02:00
[ " $( ansible-playbook test_handlers.yml -i inventory.handlers -v " $@ " --tags scenario2 -l A \
2019-08-12 22:24:28 +02:00
| grep -E -o 'RUNNING HANDLER \[test_handlers : .*?]' ) " = " RUNNING HANDLER [ test_handlers : test handler] " ]
2016-10-12 23:57:53 +02:00
2019-12-19 20:10:51 +01:00
# Test forcing handlers using the linear and free strategy
for strategy in linear free; do
2016-10-12 23:57:53 +02:00
2019-12-19 20:10:51 +01:00
export ANSIBLE_STRATEGY = $strategy
2016-10-12 23:57:53 +02:00
2019-12-19 20:10:51 +01:00
# Not forcing, should only run on successful host
[ " $( ansible-playbook test_force_handlers.yml -i inventory.handlers -v " $@ " --tags normal \
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs) " = " CALLED_HANDLER_B" ]
2016-10-12 23:57:53 +02:00
2019-12-19 20:10:51 +01:00
# Forcing from command line
[ " $( ansible-playbook test_force_handlers.yml -i inventory.handlers -v " $@ " --tags normal --force-handlers \
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs) " = " CALLED_HANDLER_A CALLED_HANDLER_B" ]
2016-10-12 23:57:53 +02:00
2019-12-19 20:10:51 +01:00
# Forcing from command line, should only run later tasks on unfailed hosts
[ " $( ansible-playbook test_force_handlers.yml -i inventory.handlers -v " $@ " --tags normal --force-handlers \
| grep -E -o CALLED_TASK_. | sort | uniq | xargs) " = " CALLED_TASK_B CALLED_TASK_D CALLED_TASK_E" ]
2016-10-12 23:57:53 +02:00
2019-12-19 20:10:51 +01:00
# Forcing from command line, should call handlers even if all hosts fail
[ " $( ansible-playbook test_force_handlers.yml -i inventory.handlers -v " $@ " --tags normal --force-handlers -e fail_all = yes \
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs) " = " CALLED_HANDLER_A CALLED_HANDLER_B" ]
2016-10-12 23:57:53 +02:00
2019-12-19 20:10:51 +01:00
# Forcing from ansible.cfg
[ " $( ANSIBLE_FORCE_HANDLERS = true ansible-playbook test_force_handlers.yml -i inventory.handlers -v " $@ " --tags normal \
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs) " = " CALLED_HANDLER_A CALLED_HANDLER_B" ]
# Forcing true in play
[ " $( ansible-playbook test_force_handlers.yml -i inventory.handlers -v " $@ " --tags force_true_in_play \
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs) " = " CALLED_HANDLER_A CALLED_HANDLER_B" ]
# Forcing false in play, which overrides command line
[ " $( ansible-playbook test_force_handlers.yml -i inventory.handlers -v " $@ " --tags force_false_in_play --force-handlers \
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs) " = " CALLED_HANDLER_B" ]
unset ANSIBLE_STRATEGY
done
2015-07-16 03:54:12 +02:00
[ " $( ansible-playbook test_handlers_include.yml -i ../../inventory -v " $@ " --tags playbook_include_handlers \
2019-08-12 22:24:28 +02:00
| grep -E -o 'RUNNING HANDLER \[.*?]' ) " = " RUNNING HANDLER [ test handler] " ]
2015-07-16 03:54:12 +02:00
[ " $( ansible-playbook test_handlers_include.yml -i ../../inventory -v " $@ " --tags role_include_handlers \
2019-08-12 22:24:28 +02:00
| grep -E -o 'RUNNING HANDLER \[test_handlers_include : .*?]' ) " = " RUNNING HANDLER [ test_handlers_include : test handler] " ]
2016-12-25 12:14:25 +01:00
2017-07-19 22:02:32 +02:00
[ " $( ansible-playbook test_handlers_include_role.yml -i ../../inventory -v " $@ " \
2019-08-12 22:24:28 +02:00
| grep -E -o 'RUNNING HANDLER \[test_handlers_include_role : .*?]' ) " = " RUNNING HANDLER [ test_handlers_include_role : test handler] " ]
2017-07-19 22:02:32 +02:00
2016-12-25 12:14:25 +01:00
# Notify handler listen
ansible-playbook test_handlers_listen.yml -i inventory.handlers -v " $@ "
# Notify inexistent handlers results in error
set +e
result = " $( ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers " $@ " 2>& 1) "
set -e
grep -q "ERROR! The requested handler 'notify_inexistent_handler' was not found in either the main handlers list nor in the listening handlers list" <<< " $result "
# Notify inexistent handlers without errors when ANSIBLE_ERROR_ON_MISSING_HANDLER=false
ANSIBLE_ERROR_ON_MISSING_HANDLER = false ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers -v " $@ "
2019-06-27 23:29:20 +02:00
ANSIBLE_ERROR_ON_MISSING_HANDLER = false ansible-playbook test_templating_in_handlers.yml -v " $@ "
2018-05-24 04:03:31 +02:00
# https://github.com/ansible/ansible/issues/36649
output_dir = /tmp
set +e
result = " $( ansible-playbook test_handlers_any_errors_fatal.yml -e output_dir = $output_dir -i inventory.handlers -v " $@ " 2>& 1) "
set -e
[ ! -f $output_dir /should_not_exist_B ] || ( rm -f $output_dir /should_not_exist_B && exit 1)
2018-10-22 17:46:36 +02:00
# https://github.com/ansible/ansible/issues/47287
2019-08-12 22:24:28 +02:00
[ " $( ansible-playbook test_handlers_including_task.yml -i ../../inventory -v " $@ " | grep -E -o 'failed=[0-9]+' ) " = "failed=0" ]
2019-03-20 14:46:19 +01:00
# https://github.com/ansible/ansible/issues/27237
set +e
result = " $( ansible-playbook test_handlers_template_run_once.yml -i inventory.handlers " $@ " 2>& 1) "
set -e
grep -q "handler A" <<< " $result "
grep -q "handler B" <<< " $result "