vagrant ansible local

Jun 26, 2016   #linux  #vagrant  #ansible  #ansible_local  #fix 

The other day I was using ansible_local provisioning for Vagrant. After the usual

vagrant up

it gave me this obsure error:

==> myserver: Running provisioner: ansible_local...
    myserver: Installing Ansible...
    The Ansible software could not be found! Please verify
    that Ansible is correctly installed on your guest system.

    If you haven't installed Ansible yet, please install Ansible
    on your Vagrant basebox, or enable the automated setup with the
    `install` option of this provisioner. Please check
    for more information.

Guess what? It is a bug in Vagrant 1.8.1. It is already fixed in 1.8.4; however, if updating Vagrant is not an option, you can as well work around this bug by adding the following code in your Vagrantfile (this snippet is for RedHat-based distributions; for Debian-based you need to change ‘shell’ line):

  # Patch for                                                                                                          
  config.vm.provision "shell", inline: 'sudo yum install -y epel-release && sudo yum install -y ansible'

  config.vm.provision "shell" do |s|
    s.inline = '[[ ! -f $1 ]] || grep -F -q "$2" $1 || sed -i "/__main__/a \\    $2" $1'
    s.args = ['/usr/bin/ansible-galaxy', "if sys.argv == ['/usr/bin/ansible-galaxy', '--help']: sys.argv.insert(1, 'info')"]