Vagrant 利用流浪汉

Vagrant 利用流浪汉,vagrant,ping,configure,ansible,Vagrant,Ping,Configure,Ansible,我刚开始用Ansible和Vagrant。我将Ansible安装在本地开发人员上,在我看来,它运行良好。我在我的项目vagrant中以以下方式创建了库存文件: vim inventory testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_user=vagrant ansible_ssh_private_key_file=/home/user/.vagrant.d/insecure_private_key

我刚开始用Ansible和Vagrant。我将Ansible安装在本地开发人员上,在我看来,它运行良好。我在我的项目vagrant中以以下方式创建了库存文件:

vim inventory
testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=/home/user/.vagrant.d/insecure_private_key
使用下面提到的说明,我得到了以下信息:

ansible testserver -i inventory -m ping
testserver | FAILED => SSH encountered an unknown error during the connection. We    
recommend you re-run the command using -vvvv, which will enable SSH debugging output to      
help diagnose the issue
配置ansible和vagrant的最佳方式是什么?
致以最诚挚的问候。

在Vagrant中,您可以使用Ansible插件,或者(如果不支持的话)返回到在线供应器。这样,您就不需要在托管VM的机器上安装Ansible。您的Vagrant文件如下所示:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "mybox" do |mybox|
    mybox.vm.box = "ubuntu/trusty64"
    mybox.vm.network "private_network", ip: "192.168.15.101"
    mybox.vm.hostname = "mybox"
    config.vm.provision "shell",
      inline: "apt-get update && apt-get install python-software-properties -y && apt-get install software-properties-common -y && apt-add-repository ppa:ansible/ansible && apt-get update && apt-get install ansible -y && cp /vagrant/hosts /etc/ansible/hosts"
    if Vagrant.has_plugin?("vagrant-ansible-local")
      config.vm.provision "ansibleLocal", playbook: "playbook.yml"
    else
      config.vm.provision "shell",
        inline: "ansible-playbook /vagrant/playbook.yml"
    end
  end
end
确保
playbook.yml
与文件位于同一目录中

  • vagrant up
    将启动虚拟机,然后安装Ansible并运行playbook
  • 流浪规定
    将重新运行剧本

此外,您可以使用
ansible playbook/vagrant/playbook.yml执行
vagrant ssh
并在VM内运行playbook,以防有人遇到同样的问题,解决方案是只使用一行,不使用反斜杠。比如说


testserver ansible\u ssh\u host=127.0.0.1 ansible\u ssh\u port=2222 ansible\u ssh\u user=vagrant ansible\u private\u key\u file=.vagrant/machines/default/virtualbox/private\u key

-vvv
重新运行
ansible
,并添加该输出。我解决了这个问题:我必须在同一行上给出该语句,不能跳转:testserveransible\u ssh\u host=ip ansible\u ssh\u port=my\u port ansible\u ssh\u private\u key\u file=my\u file能否请您添加此作为答案并接受它:我遇到了相同的问题,几乎错过了注释中的解决方案