通过Vagrant自动安装和运行Ansible Local
我正在使用Vagrant并试图使Ansible能够使用它。因为我在使用Python 3.5.0的通过Vagrant自动安装和运行Ansible Local,vagrant,ansible,Vagrant,Ansible,我正在使用Vagrant并试图使Ansible能够使用它。因为我在使用Python 3.5.0的virtualenv中工作,所以我必须使用Ansible Local–由于我没有运行Python 2.x,“主”Ansible将不会在我的主机上运行 不管怎样,一切都正常,除了vagrant up找不到Ansible。以下是调用的输出: ==> default: Running provisioner: ansible_local... default: Installing Ansib
virtualenv
中工作,所以我必须使用Ansible Local–由于我没有运行Python 2.x,“主”Ansible将不会在我的主机上运行
不管怎样,一切都正常,除了vagrant up
找不到Ansible。以下是调用的输出:
==> 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.
但是,如果我使用vagrant ssh
访问VM,Ansible显然已安装:
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已经插入到服务器中,并且工作正常。然而,我使用Ansible的全部意义在于,我可以通过Vagrant自动运行它。以下是我的流浪汉档案的相关部分:
config.vm.provision "ansible_local" do |ansible|
ansible.install = true
ansible.version = "latest"
ansible.sudo = true
ansible.playbook = "server.yml"
end
如有任何建议,我们将不胜感激。谢谢大家! 在调试模式下打开该框:
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's version number and exit
DEBUG ssh: Exit status: 5
ansible galaxy——帮助是问题所在,因为它期望采取行动。因为失败了,vagrant认为安装有问题
看起来这个问题已经在上解决了,并且将在下一个版本中解决
您可以尝试的是:
# -*- 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
或者,在等待修复程序发布时,另一个选项是构建。您是否可以尝试在Provisionier中添加
ansible.version=“latest”
part@Fr我试过了,但还是得到了同样的结果。
# 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