Automatically installing and starting Ansible Local through Vagrant

I use Vagrant and try to allow Ansible to work with it. Since I work virtualenvwith Python 3.5.0, I have to use Ansible-Local - the "main" Ansible will not work on my host because I do not run Python 2.x.

Despite this, everything works mostly, except that it vagrant updoes not find Ansible. Here is the result of the call:

==> default: Running provisioner: ansible_local...
    default: 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
https://docs.vagrantup.com/v2/provisioning/ansible_local.html
for more information.

However, if I use vagrant sshto access the virtual machine, Ansible is explicitly installed:

vagrant@vagrant-ubuntu-trusty-64:~$ ansible --version
ansible 2.0.0.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

, . ansible-playbook server.yml, SSH'd - , . , Ansible , Vagrant. Vagrantfile:

  config.vm.provision "ansible_local" do |ansible|
      ansible.install = true
      ansible.version = "latest"
      ansible.sudo = true
      ansible.playbook = "server.yml"
  end

. !

+4
1

:

VAGRANT_LOG=debug vagrant up

:

DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: ansible-galaxy --help && ansible-playbook --help (sudo=false)
DEBUG ssh: stderr: ERROR! Missing required action

DEBUG ssh: stdout: Usage: ansible-galaxy [delete|import|info|init|install|list|login|remove|search|setup] [--help] [options] ...

Options:
  -h, --help     show this help message and exit
  -v, --verbose  verbose mode (-vvv for more, -vvvv to enable connection
                 debugging)
  --version      show program version number and exit

DEBUG ssh: Exit status: 5

ansible-galaxy --help - , . , , .

, .

:

# -*- mode: ruby -*-
# vi: set ft=ruby :

$install_ansible = <<SCRIPT
apt-get -y install software-properties-common
apt-add-repository ppa:ansible/ansible
apt-get -y update
apt-get -y install ansible

SCRIPT

Vagrant.configure(2) do |config|
  config.vm.box = 'ubuntu/trusty64'
  config.vm.provision 'shell', inline: $install_ansible
  # Patch for https://github.com/mitchellh/vagrant/issues/6793
  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')"]
  end
  config.vm.provision :ansible_local do |ansible|
    ansible.sudo = true
    ansible.playbook = 'server.yml'
  end
end

: MasonM :

# Patch for https://github.com/mitchellh/vagrant/issues/6793
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')"]
end 

, , .

+9

Source: https://habr.com/ru/post/1628009/


All Articles