Reuse a role in different playbooks

29 views
Skip to first unread message

Alan Evangelista

unread,
Sep 1, 2016, 4:57:29 PM9/1/16
to Ansible Project
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?

Dick Davies

unread,
Sep 2, 2016, 7:12:56 AM9/2/16
to ansible list
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.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/2b9ff3ae-78a3-4239-a6c1-cb6a854a066e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages