Vagrant's ansible_local
is probably not a good choice as it is not very flexible.
I achieve a similar setup by using the shell
provisionier and an inline script in the Vagrantfile
:
Vagrant.configure(2) do |config|
config.vm.synced_folder ".", "/vagrant"
config.vm.box = "deb/wheezy-amd64"
config.ssh.forward_agent = true
$script = <<SCRIPT
sudo apt-get update
sudo apt-get install python2.7-dev -qq
sudo apt-get install python-pip -qq
sudo easy_install pip
sudo pip install markupsafe ansible
sudo rm -rf /etc/ansible
sudo mkdir -p /etc/ansible/roles
cd /vagrant
sudo ansible-galaxy install -r requirements.yml -p roles/ --force
# Add ansible.cfg to pick up roles path.
echo '[defaults]' >> /etc/ansible/ansible.cfg
echo 'roles_path = /etc/ansible/roles/' >> /etc/ansible/ansible.cfg
sudo -E -s ansible-playbook -vv -i /vagrant/local-test/inventory /vagrant/local-test/site.yml --connection=local
SCRIPT
# Vagrant.configure("2") do |config|
config.vm.provision "shell", run: "always", inline: $script, privileged: "false"
end
old answer
If you run a task
shell: ansible-galaxy install ...
Ansible will install the role on the target system, not the system executing ansible-playbook
. But Ansible will look for the roles
of a play on the control system.
Best way to handle this is IMHO:
- create a
requirements.yml
containing the roles your play needs
- install the roles with
ansible-galaxy install -r requirements.yml
Take a look at the documentation for parameters of the requirements.yml