0
votes

I have a role which configures /etc/network/interfaces.d/ethX. It has handler 'restart interface' which is called through notifications.

But there are few programs which are listen on that interface and should be restarted if I changed anything in configuration of that interface.

Normally I could send notify to restart handler of the role which configures application, but here a catch: Role to configure interface is a rather generic one and could be called from different playbooks together with different application's roles. I couldn't hardcode notify to handlers for those roles, but, nonetheless I want to restart all 'dependent' on that interface applications.

Does Ansible has some kind of 'subscribe' feature for notifications? I knew that Chef does, so may be Ansible can do this too? Other way I thought is some kind of 'soft notifications' from interface configuration role which don't fail if there is no such handler.

Any ideas?

1

1 Answers

3
votes

Yes, Ansible does have a listener feature since version 2.2.

Handlers' namespace is common, so it's enough to assure the roles containing specific handlers are assigned (unless you used flush_handlers in one of the roles, in which case you'd need to ensure a role containing the handler you wish to run, is assigned before the actual flush operation).