Vagrant 飘忽不定的SSH错误
我正试着做一些流浪的事情,但从一开始就遇到了问题。这是我的流浪汉档案:Vagrant 飘忽不定的SSH错误,vagrant,ansible,Vagrant,Ansible,我正试着做一些流浪的事情,但从一开始就遇到了问题。这是我的流浪汉档案: # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" config.vm.network "private_network", ip: "192.168.6.66" config.vm.provider "virtualbox" do |vb|
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.6.66"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "site.yml"
end
end
yml只是
---
- name: Bring up server with MySQL, Nginx, and PHP-FPM
hosts: all
remote_user: root
roles:
- common
而common/tasks/main.yml是
---
- name: Update apt
apt: update_cache=yes
执行vagrant up
时,输出为
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Setting the name of the VM: ansible-provision_default_1412793587231_72507
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 => 2200 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Checking for host entries
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/bram/Projects/Brammm/ansible-provision
==> default: Running provisioner: ansible...
PLAY [Bring up server with MySQL, Nginx, and PHP-FPM] *************************
GATHERING FACTS ***************************************************************
fatal: [default] => 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
TASK: [common | Update apt] ***************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/bram/site.retry
default : ok=0 changed=0 unreachable=1 failed=0
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
如果我查看.vagrant/provisioners/ansible/inventory/vagrant\u ansible\u inventory,我会看到以下内容:
default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200
我希望那里的IP与专用网络中设置的IP相同?我已经盯着这个看了一个多小时了,我做错什么了吗?我有一种感觉,IP设置不正确或是什么的。我可以
ping192.168.6.66
Vagrant将创建自己的ansible库存文件(您已经看到),默认值为127.0.0.1和2200
您需要使用ansible.inventory\u path
与Vagrant一起使用的非常简单的清单文件可能如下所示:
默认ansible_ssh_host=192.168.111.222,其中上述IP地址为
在您的文件中设置一个:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.6.66"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "site.yml"
end
end
config.vm.network:private_网络,ip:“192.168.111.222”
从这里,您的
site.yml
覆盖了远程用户ansible将用于root的问题。但是,您没有为它提供私钥,也没有提供密码
因此,我修正了将ansible\u ssh\u user
设置为“vagrant”,因为它是默认的已知用户,如果不覆盖远程用户,ansible的行为将与vagrant ssh
相同。并将sudo
设置为true,因为“流浪”用户是sudoer,而不是su
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.6.66"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "site.yml"
ansible.extra_vars = { ansible_ssh_user: 'vagrant' }
ansible.sudo = true
#ansible.verbose = 'vvvv'
end
end
请参阅“为什么ANSIBLE PROVISIONER以错误的用户身份连接?”部分我在Vagrant 1.7上尝试以
根用户身份连接ANSIBLE,可能是因为一些单独的部署回购组变量默认设置。可能的修复方法:
- 设置或适当设置
- 或者移动到Vagrant 1.8,根据
我遇到了类似的问题,无论出于何种原因,它都无法通过ssh连接到服务器
vagrant ssh
工作正常,但由于超时,vagrant provision
将无法使用ssh
我终于把这些点连接起来,意识到这实际上是因为我的雇主让我们使用的VPN客户端。Cisco AnyConnect VPN客户端进行了某种错误处理,因此我必须重新启动整个工作站才能运行它
幸运的是,我在很多事情上都不必连接到VPN,因此这种情况对我来说只是偶尔发生。我们建议您使用-vvv重新运行该命令,这将启用SSH调试输出来帮助诊断问题。
您这样做了吗?