Karl Amort
Karl Amort

Reputation: 16394

Best-practice for using an ansible role from galaxy in multiple roles?

I am working on an ansible playbook for our infrastructure. I have the following recurring need for which I have yet to find a recommended pattern:

I have a server that needs to run multiple vhosts (/databases/rbenv environment/etc). I can install nginx (postgres/rbenv/etc) with a dependency on a role from galaxy, i. e.

dependencies:
- role: "geerlingguy.nginx"
  nginx_ppa_use: true
  nginx_ppa_version: development
  ..

Now I could add an array of vhost configurations to this dependency. However, I'd like to bundle these definitions not by technology (nginx/rbenv...) but by project.

The best path I have found so far is to repeat the nginx dependency in each project role. But that results in the duplication of all the global nginx options and repeated execution of the nginx installation when provisioning a fresh server.

Upvotes: 0

Views: 418

Answers (1)

Xiong Chiamiov
Xiong Chiamiov

Reputation: 13744

That seems fine to me.

The best path I have found so far is to repeat the nginx dependency in each project role. But that results in the duplication of all the global nginx options and repeated execution of the nginx installation when provisioning a fresh server.

It shouldn't, because Ansible is built to only do things if the system state is not in the desired state (i.e. install nginx only if nginx isn't already installed).

However, if the repeated checks are taking longer than you like, you could split out the role into two: one that does the basic, common setup, and one that gets repeated for every vhost.

Upvotes: 2

Related Questions