Reuse a role in different playbooks

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?

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.