# re-using role handlers

**URL:** <https://forum.ansible.com/t/re-using-role-handlers/14162>\
**Category:** Ansible Project\
**Created:** [December 16, 2013, 5:35pm UTC](https://forum.ansible.com/t/re-using-role-handlers/14162 "2013-12-16T17:35:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [December 16, 2013, 5:35pm UTC](https://forum.ansible.com/t/re-using-role-handlers/14162/1 "2013-12-16T17:35:26Z")

</div>

Hello,

I have a role handler that I use to restart instances of node-logstash ; basically it does

// roles/logstash/handlers/main.yml

- name: restart logstash service  
service: name={{ item.initd\_script }} state=restarted  
sudo: yes  
sudo\_user: root  
when: item.state == “started”  
with\_items: instances

where instances is defined in // roles/logstash/vars/main.yml

the role also takes care of node-logstash installation.

I would like to re-use this handler from another play where the role is not invoked but it breaks because since the role is not invoked, the handler is not defined (and the variable either).

I cannot just include the handler file because I will miss the vars.

Is there a possibility to invoke a role without playing its tasks / dependencies ?

Do you see a way to organize things so that this handler, along with its vars could be called easily from another play ? should I create a new role “logstash\_common” with an empty “tasks” directory and invoke it where I need the handler ?

Thanks

---

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [December 17, 2013, 2:59pm UTC](https://forum.ansible.com/t/re-using-role-handlers/14162/2 "2013-12-17T14:59:24Z")

</div>

Hi Jerome,  
Like you suggested I think like what I would do is create a common  
role that is included as a role dependency that includes the common  
handlers that need to be invoked from multiple roles:

{some\_other\_role, logstash}/meta/main.yml:

dependencies:  
- common

-John
