I'm pretty new to Ansible (running version 2.2.1.0), and so I have been following the basic directory structure so far. Recently I tried to move some tasks to the handlers
area, but I'm getting some odd behavior.
My tree structure looks like:
host_inventory
host_vars
site.yml
roles
common
handlers
main.yml
meta
main.yml
tasks
main.yml
vars
main.yml
There are really only two relevant files (I think).
This version of tasks/main.yml DOES call the handler:
roles/common/tasks/main.yml:
---
- name: make test file
shell: "touch /home/hello"
notify: say goodbye
and in roles/common/handlers/main.yml:
---
- name: say goodbye
shell: "touch /home/goodbye"
This does NOT call the handler:
roles/common/tasks/main.yml
---
- name: test for file
stat:
path: /home/hello
notify: say goodbye
roles/common/handlers/main.yml
---
- name: say goodbye
shell: "echo something"
I can't understand why my stat
tasks are not calling their handlers.
Can anyone provide some insight? I feel like I'm missing something obvious.
Handlers are notified only when task state is changed
.
In your example shell
task is always in changed
state, but stat
task is always in ok
state.
See documentation for more details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.