What is the equivalent of r10k in Ansible?

Based on the discussion with @ceejayoz the conclusion is that Ansible's equivalent of Puppet's R10K is ansible-galaxy install -r requirements.yml.


In R10K a Puppetfile is used. A Puppetfile is a definition of modules (e.g. from Puppetforge) that need to be assembled in a certain environment, e.g. the Puppetfile of the development environment could look as follows:

mod 'garethr/docker', '5.3.0'
mod 'unibet/vagrant', '0.2.1'

mod 'jenkins',
  :git => 'https://github.com/jenkinsci/puppet-jenkins',
  :ref => 'master'

mod 'jdk_oracle',
  :git => 'https://github.com/schrepfler/puppet-jdk_oracle.git',
  :ref => 'master'

While the Production Puppetfile contains stable versions:

mod 'garethr/docker', '5.2.0'
mod 'unibet/vagrant', '0.2.0'
mod 'schrepfler/puppet-jdk_oracle', '0.2.0'
mod 'rtyler/jenkins', '1.6.1'

The equivalent of r10k in ansible

In order to assemble roles (equivalent of Puppet's modules) from Puppet's Puppetforge equivalent in Ansible - Ansible Galaxy or custom sources the roles or sources could be defined in yml files (based on the link provided by @ceejayoz and this link). The development environment could look as follows:


- src: geerlingguy.composer
  version: 1.3.0

- src: geerlingguy.java
  version: 1.2.1

- src: bennojoy.mysql

- src: https://github.com/ANXS/postgresql.git
  version: master

and it could be run by issuing sudo ansible-galaxy install -r development.yml. While the production could look like:


- src: geerlingguy.composer
  version: 1.2.0

- src: geerlingguy.java
  version: 1.1.1

and be run by executing sudo ansible-galaxy install -r production.yml. The outcome could look as follows:

user@host ~ $ sudo ansible-galaxy install -r development.yml
- geerlingguy.composer is already installed, skipping.
- downloading role 'java', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-java/archive/1.2.1.tar.gz
- extracting geerlingguy.java to /etc/ansible/roles/geerlingguy.java
- geerlingguy.java was installed successfully
- bennojoy.mysql is already installed, skipping.

Think ansible-galaxy is only half of the answer because it doesn't do anything about Ansible playbooks, which are synonymous to Puppet role modules. One of the benefits of r10k is that you can manage all aspects of each environment separately.

You might consider separate branches per environment with all of the Ansible roles being pulled in via ansible-galaxy. This would let you isolate playbook, inventory, and role changes per environment without unintentionally letting them slip into production and not duplicating role logic per branch.