0

The Problem

For a test, I set up a very simple Vagrant file. This is just to test how working with Ansible is. Sadly I am stuck at step number 2 with the following error during vagrant up --provision (which I can repeat on reload):

The executable 'ansible-playbook' Vagrant is trying to run was not found in the PATH variable. This is an error. Please verify this software is installed and on the path.


The Debugging Efforts so far

As the Ubuntu 14 "Trusty" 64bit box comes without Ansible installed, I added a quick shell script to run as provisioner before the actual Ansible playbooks. Here's the Vagrantfile

Vagrant.require_version ">= 1.7.0"

Vagrant.configure("2") do |config|

    config.vm.box = "ubuntu/trusty64"

    config.ssh.insert_key = false

    # Synced folders
    config.vm.synced_folder "./public", "/var/www",
        disabled: false

    # Install Ansible
    config.vm.provision :shell,
        path: "provisioners/shell/install-ansible.sh"

    # Run Ansible Playbooks
    config.vm.provision "ansible" do |ansible|
        ansible.verbose = "vvv"
        ansible.playbook = "provisioners/ansible/playbook.yml"
    end
end

The bash script install-ansible.sh is as simple as this:

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get -y update
sudo apt-get install ansible

To confirm that ansible-playbook and ansible are installed, I vagrant sshed into the box and called which ansible-playbook and which ansible. Both are available:

$ which ansible
# /usr/bin/ansible

Looking at dpkg -L ansible, I find plenty of stuff going on in /etc and /usr/bin. Also python --version gives me Python 2.7.6 while the minimum required version is 2.4.

The echo $PATH gives the following default output:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

I can confirm, that the user is the correct one: whoami results in vagrant and the last command executed before the error is:

PYTHONUNBUFFERED=1 
ANSIBLE_HOST_KEY_CHECKING=false 
ANSIBLE_FORCE_COLOR=true 
ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s' 
ansible-playbook 
    --user=vagrant 
    --connection=ssh 
    --timeout=30 
    --limit='default' 
    --inventory-file=/Users/*****/projects/*****/.vagrant/provisioners/ansible/inventory 
        -vvv 
        provisioners/ansible/playbook.yml

I am out of ideas here.

6

I think you got a misconception here. There is no need to install Ansible inside the Vagrant box. Ansible is agentless. Ansible uses SSH (or other protocols) to connect to other hosts. So there is no need to have Ansible executable inside the host.

You just need to have Ansible installed on the host running vagrant.

If you want to run Ansible inside the Vagrant box (what is IMHO not the way Vagrant and Ansible are supposed to work together) you will need to change the vm.provision step of the Vagrant file as well. As vm.provision "ansible" will look for Ansible executable on the host you run vagrant on you should change to vm.provision "shell" and put the ansible-playbook command inside the shell script, which should look for Ansible executable on the Vagrant box.

  • Why would that not be possible? When look at for e.g. support for Windows, then you anyway need a man-in-the-middle machine to execute commands. Why not use the already existing VM? – kaiser Dec 15 '15 at 13:29
  • Windows support is an exception. That does not change that 'config.vm.provision "ansible" do |ansible|' looks for Ansible executable on the host running vagrant, not the vagrant box. – Henrik Pingel Dec 16 '15 at 14:43
  • Sad as it is: You are right. Seems like for some reason other provisioners do not have to be added to the host machine that is running Vagrant, but for Ansible it is. Thanks for your answer. – kaiser Dec 17 '15 at 13:01
  • I don't know too much about other provisioners but there must be a control machine installed somewhere. Ansible has a push architecture whereas most other provisioners use pull mechanisms. You can use pull mechanism with Ansible as well, but that won't remove the need to install Ansible on the vagrant box. – Henrik Pingel Dec 17 '15 at 13:38
  • With installing Anisble inside the Vagrant box, I have no problem. Will see how far I get with that pointer. Thanks! – kaiser Dec 19 '15 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.