Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change ansible role_path with vagrant provision

I have a bunch of ansible galaxy roles and a bunch of custom roles.

The problem is that I can't load custom roles AND galaxy roles at the same time using a Vagrantfile :ansible provisionner.

Without vagrant, this command works well as I added the ANSIBLE_ROLES_PATH environment variable:

 ANSIBLE_ROLES_PATH=./custom_roles ansible-playbook project.yml --inventory dev.ini -vvvv --ask-sudo-pass

My Vagrant configuration is the following:

config.vm.provision :ansible do |ansible|
   ansible.raw_arguments = ['--timeout=300']
   ansible.playbook = "project.yml"
   ansible.verbose = "vvv"
   ansible.groups = {
     "env-dev:children" => ["app-web", "app-db"],
     "app-web" => ["my-app"],
     "app-db" => ["my-app"],
   }
 end

I can see that ansible auto-load roles inside ./roles but I can't add my custom roles to this directory due to version control (./roles is in my .gitignore)

Here is the directory structure to have a better view of what's going on:

 - roles/
     - postgresql/...
     - php/...
 - custom_roles/
     - my-role-1/...
     - my-role-1/...
 - .gitignore         <- ignore ./roles
 - project.yml
 - roles.yml
 - dev.ini
 - Vagrantfile
like image 233
Clément Prévost Avatar asked Apr 28 '16 15:04

Clément Prévost


1 Answers

So I had the same problem, and found a workaround by setting the ANSIBLE_ROLES_PATH environment variable.

In the Vagrantfile:

Vagrant.configure('2') do |config|
  vagrant_root = File.dirname(__FILE__)
  ENV['ANSIBLE_ROLES_PATH'] = "#{vagrant_root}/infrastructure/provisioning/ansible/roles:#{vagrant_root}/infrastructure/provisioning/ansible/galaxy-roles"

  # ansible provisioning
  config.vm.provision :ansible do |ansible|
    ansible.playbook = 'infrastructure/provisioning/ansible/playbook.yml'
    ansible.galaxy_role_file = 'infrastructure/provisioning/ansible/dependencies.yml'
    ansible.galaxy_roles_path = 'infrastructure/provisioning/ansible/galaxy-roles'
  end
end
like image 75
Thomas Ploch Avatar answered Nov 09 '22 02:11

Thomas Ploch