# Reuse a role in different playbooks

**URL:** <https://forum.ansible.com/t/reuse-a-role-in-different-playbooks/22457>\
**Category:** Ansible Project\
**Created:** [September 1, 2016, 8:13pm UTC](https://forum.ansible.com/t/reuse-a-role-in-different-playbooks/22457 "2016-09-01T20:13:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Evangelista](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Alan\_Evangelista](https://forum.ansible.com/u/Alan_Evangelista)\
**Post date:** [September 1, 2016, 8:13pm UTC](https://forum.ansible.com/t/reuse-a-role-in-different-playbooks/22457/1 "2016-09-01T20:13:57Z")

</div>

I current have one playbook for each application in my infrastructure: one for Gerrit, one for Jenkins, etc. Current filesystem structure:

playbooks

> 

---- gerrit

> 

— roles

> 

---- postfix  
---- jenkins

> 

— master.yml  
— roles

> 

---- postfix

My Jenkins master node setup playbook has something like:

- name: Setup Jenkins master node  
hosts: jenkins-master  
remote\_user: root  
roles:
- selinux
- epel
- packages
- user
- sudo
- jenkins
- nginx
- systemd
- firewalld
- nfs
- ssh
- postfix

The gerrit setup playbook is similar.

- name: Setup Gerrit  
hosts: gerrit  
remote\_user: root  
roles:
- selinux
- epel
- packages
- gerrit
- systemd
- firewalld
- postfix

I’d like to reuse the postfix email server role used in Gerrit playbook in the Jenkins playbook. Currently, it is duplicated. Is that possible or should I use a different Ansible files organization to achieve the reuse I desire?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [September 2, 2016, 11:12am UTC](https://forum.ansible.com/t/reuse-a-role-in-different-playbooks/22457/2 "2016-09-02T11:12:49Z")

</div>

I'd put both those plays into site.yml , just targeting different host  
groups, and have a single roles/ directory.

If you'd prefer, there's nothing wrong with a jenkins.yml and  
gerrit.yml up in the same folder  
as site.yml.
