Skip to content

Instantly share code, notes, and snippets.

@darKoram
Last active August 29, 2015 14:05
Show Gist options
  • Save darKoram/0a38cce21a607dacb338 to your computer and use it in GitHub Desktop.
Save darKoram/0a38cce21a607dacb338 to your computer and use it in GitHub Desktop.
test ansible force_handlers
I'd like to force handlers to run even if a host fails on a task. Sort of like a tearDown() in a test harness.
# force_handlers/handlers/main.yml
- name: Run handler
shell: echo "running handler"
(master)] ansible-playbook -i hosts force_handlers.yml --force-handlers
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [force_handlers | Step1. notify on this step] **************************
changed: [localhost]
TASK: [force_handlers | Fail by force] ****************************************
skipping: [localhost]
TASK: [force_handlers | Next step] ********************************************
changed: [localhost]
NOTIFIED: [force_handlers | Run handler] **************************************
changed: [localhost]
PLAY RECAP ********************************************************************
localhost : ok=4 changed=3 unreachable=0 failed=0
# force_handlers/tasks/main.yml
- name: Step1. notify on this step
shell: echo "Step1"
notify: Run handler
- name: Fail by force
fail: msg="failing"
- name: Next step
shell: echo "next step"
[kbroughton@mb-kbroughton:git/test_ansible +
(master)] ansible-playbook -i hosts force_handlers.yml --force-handlers -e "cli_arg=yes"
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [force_handlers | Step1. notify on this step] **************************
changed: [localhost]
TASK: [force_handlers | Fail by force] ****************************************
failed: [localhost] => {"failed": true}
msg: failing
NOTIFIED: [force_handlers | Run handler] **************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/kbroughton/force_handlers.retry
localhost : ok=2 changed=1 unreachable=0 failed=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment