Ansible not found in PATH after installation on Vagrant box
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.
Related videos on Youtube
kaiser
You came here to know more about me? Here you go! I have been moderator on WordPress.StackExchange for several years. You can find me @unserkaiser on Twitter, where I also talk about building @gtmifylab, my current indie side project. Some of my older code bits can be found on GitHub franz-josef-kaiser. If you want to get in touch with me, then go with [email protected]. Please understand, that this isn't an additional support route and I won't answer such requests. Best wishes and keep building! Kaiser.
Updated on September 18, 2022Comments
-
kaiser over 1 year
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 onreload
):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
andansible
are installed, Ivagrant ssh
ed into the box and calledwhich ansible-playbook
andwhich 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
. Alsopython --version
gives mePython 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 invagrant
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.
-
kaiser over 8 yearsWhy 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?
-
Henrik Pingel over 8 yearsWindows 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.
-
kaiser over 8 yearsSad 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.
-
Henrik Pingel over 8 yearsI 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.
-
kaiser over 8 yearsWith installing Anisble inside the Vagrant box, I have no problem. Will see how far I get with that pointer. Thanks!
-
Henrik Pingel over 8 yearsYou might want to checkout this blog post for a better setup.