201606.05

Ansible: included handlers not running in v2.x

I’ll keep this short. I recently installed Ansible 2.0 to manage the Turtl servers. However, once I ran some of the roles I used in the old version, my handlers were not running.

For instance:

# roles/rethinkdb/tasks/main.yml

- name: copy rethinkdb monitrc file
  template: src=monit.j2 dest=/etc/monit.d/rethinkdb
  notify: restart monit
# roles/rethinkdb/handlers/main.yml

- include roles/monit/handlers/main.yml
# roles/monit/handlers/main.yml

- name: restart monit
  command: /etc/rc.d/rc.monit restart

Note that in Ansible <= 1.8, when the monitrc file gets copied over, it would run the restart monit handler. In 2.0, no such luck.

The fix

I found this github discussion which led to this google groups post which says to put this in ansible.cfg:

[defaults]
...
task_includes_static = yes
handler_includes_static = yes

This makes includes pre-process instead of being loaded dynamically. I don’t really know what that means but I do know it fixed the issue. It breaks looping, but I don’t even use any loops in ansible tasks, so

Do whatever you want, you little weasel. I don't care. I DON'T CARE.