handler invoked from role is not called

hi,

If I use the handler incorrectly, please let me know.

I’m using Ansible a quiet while and recently migrated from 1.9 to 2.1.0.0.
My target host is CentOS 6.5
I try to follow the documentation, but can’t make the handlers work.

The playbook structure is generated by ansible-galaxy init projectname,
and I use the following logic:
site.yml has lines something like:

  • name: single node setup of projectname
    vars_files:
  • vars/main.yml
    hosts: node01
    become: true
    roles:
  • base

Logical structure:

site.yml
└── roles
└── base
└── tasks
└── main.yml

Example line in main.yml:

  • name: configure iptables rules
    template: src=iptables_config.j2 dest=/etc/sysconfig/iptables owner=root group=root mode=0600
    notify:
  • iptables restart

In roles directory I have a task with main.yml, and from that main.yml I add package configuration with template.
When the template is updated, I have a handler called, but for some reason it’s not executed.

Handlers are in same level as site.yml:

└── handlers
└── main.yml

Example line in handlers/main.yml:

  • name: iptables restart
    service: name=iptables state=restarted

I expect the handler take action when the template updates the iptables configuration file, but it’s never called.
This issue is not specific to the above example.

Regards,
Szabolcs

Try moving your handlers folder into the role, same level as your tasks under base.

  roles
   └── base
        ├── tasks
        │ └── main.yml
        └── handlers
             └── main.yml