我遵循了http://docs.ansible.com/ansible/guide_vagrant.html
的官方教程我的Vagrantfile
看起来像是:
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'bento/centos-7.2'
# SSH default root user
config.ssh.username = 'root'
config.ssh.password = 'vagrant'
# Networking
# config.vm.network :private_network, ip: '192.168.33.16'
# Provisioning
config.vm.provision :ansible do |ansible|
ansible.playbook = 'playbooks/main.yml'
end
end
我的test.sh
脚本:
ansible-playbook \
--private-key=.vagrant/machines/default/virtualbox/private_key \
-u vagrant \
-i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory \
playbooks/main.yml \
$@
但是当我运行脚本时,我收到以下错误:
fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
to retry, use: --limit @playbooks/main.retry
PLAY RECAP *********************************************************************
default : ok=0 changed=0 unreachable=1 failed=0
如何使用ansible-playbook
测试Vagrant
?
答案 0 :(得分:0)
如果你想对主机运行ansible,那么Vagrant已经拥有ansible_local配置器。
要运行此操作,您必须先在来宾计算机上安装ansible
(如果尚未安装)。这可以通过easy_install
或pip
的Vagrantfile shell配置程序完成。