0

I have a couple of different machine types that all need to have the official postgres APT repo defined for them in order to be able to apt-get install the right version of tools. These different machines all need to share the following:

---
- name: add postgres repo key
  sudo: yes
  apt_key: url=http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc
           id=ACCC4CF8

- name: add postgres repo
  sudo: yes
  apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ {{ ansible_distribution_release }}-pgdg main'

I have two roles that depend on it, my nagios role (needs to do a bunch of psql work) and my postgres-base role. It'd be fantastic if I could have both of those roles somehow include the same file / tasks above.

Right now I have created a separate role for the tasks, called it postgres-repo and I'm using ansible's role dependencies to make sure that both the roles above run postgres-repo before executing.

This is their meta/main.yml:

---
dependencies:
  - postgres-repo

Is that the best I can do? Is there a more lightweight approach than making a separate role?

Alexandr Kurilin
  • 546
  • 1
  • 8
  • 20
  • 1
    I agree with Serge Van Ginderachter. It is normal to have many small roles. However, I avoid creating dependencies, unless I need to pass parameters to the included role. Instead, what I would do would be to add `postgres-repo` to the playbook in `site.yml`. – Antonis Christofides Mar 17 '15 at 11:31

1 Answers1

2

That seems the best option to me; roles are about doing 1 thing and doing it well :)