您的剧本的精简版本中的“错误”是debug
永远不会向 ansible 报告,changed
因此,处理程序不会触发。
在这个我rescue
debug
用 a替换你的剧本中shell
,处理程序被称为
---
- hosts: all
handlers:
- name: handler
debug:
msg: handler
tasks:
- name: deploy block
block:
- name: debug meta
debug:
msg: in the block
- fail:
msg: failing
rescue:
- name: Something went wrong handler
shell: date
notify: handler
结果是
TASK [debug meta] **************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "in the block"
}
TASK [fail] ********************************************************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "failing"}
TASK [Something went wrong handler] ********************************************************************************************************************************************************************************************************************************************
changed: [localhost]
RUNNING HANDLER [handler] ******************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "handler"
}