2015-09-03 52 views
1

我一直在试图在我建立的Vagrant盒子上使用我的YML文件,这是CentOS。但是,我遇到了这个超时在所有时间:Ansag超时Vagrant

[email protected]:~/Desktop/vagrant$ vagrant provision 
[default] Running provisioner: ansible... 

PLAY [Show off some basic Ansible features] *********************************** 

GATHERING FACTS *************************************************************** 
<10.0.x.x> ESTABLISH CONNECTION FOR USER: vagrant 
<10.0.x.x> REMOTE_MODULE setup 
<10.0.x.x> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/ryan/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=2222', '-o', 'IdentityFile=/home/ryan/.vagrant.d/insecure_private_key', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=vagrant', '-o', 'ConnectTimeout=10', '10.0.x.x', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441243799.45-82681900071220 && echo $HOME/.ansible/tmp/ansible-tmp-1441243799.45-82681900071220'"] 
fatal: [default] => SSH encountered an unknown error. The output was: 
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014 
debug1: Reading configuration data /home/ryan/.ssh/config 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 19: Applying options for * 
debug1: auto-mux: Trying existing master 
debug1: Control socket "/home/ryan/.ansible/cp/ansible-ssh-10.0.x.x-2222-vagrant" does not exist 
debug2: ssh_connect: needpriv 0 
debug1: Connecting to 10.0.x.x [10.0.x.x] port 2222. 
debug2: fd 3 setting O_NONBLOCK 
debug1: connect to address 10.0.x.x port 2222: Connection timed out 
ssh: connect to host 10.0.x.x port 2222: Connection timed out 


TASK: [common | Install postgres] ********************************************* 
FATAL: no hosts matched or all hosts have already failed -- aborting 


PLAY RECAP ******************************************************************** 
      to retry, use: --limit @/home/ryan/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. 

我期待所有在互联网上找出原因,它不断超时又上来什么都没有,所以我要求计算器用于任何类型的建议。这里是我的VagrantFile样子:

VAGRANTFILE_API_VERSION = "2" 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    # All Vagrant configuration is done here. The most common configuration 
    # options are documented and commented below. For a complete reference, 
    # please see the online documentation at vagrantup.com. 

    # Every Vagrant virtual environment requires a box to build off of. 
    config.vm.box = "cento" 

    config.vm.provision "ansible" do |ansible| 
     ansible.groups = { 
       "vagrant" => ["10.0.x.x"] 
     } 
     ansible.extra_vars = { ansible_ssh_user: "vagrant" } 
     ansible.sudo = true 
     ansible.verbose = "vvvv" 
     ansible.playbook = "site.yml" 
     ansible.inventory_path = "hosts" 
    end 
end 

而我的主机文件我使用:

[vagrant] 
default ansible_ssh_host=10.0.x.x ansible_ssh_user=vagrant ansible_ssh_port=2222 

有没有人有,为什么当我运行vagrant provision任何理由,超时我?

更新: 我刚才使用默认的流浪汉主机文件的尝试:

Generated by Vagrant 

default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 

有没有办法从环回地址更改默认ansible_ssh_host到它的实际的IP?

+0

如果使用ansible_ssh_port = 22而不是2222连接到10.0.x.x,会发生什么情况?当Vagrant配置环回地址时,它会设置端口转发,但仅在127.0.0.1上设置,而不是在真实IP上。 – nikobelia

+0

它仍然超时。我试过连接端口22和2222 – ryekayo

+0

嗯。接下来要缩小的范围是,如果VM不在监听传入连接,或者您的凭证无法正常工作。 尝试使用'ssh -i〜/ .vagrant.d/insecure_private_key -p 2222 [email protected] -vvv'自己打开与主机的SSH连接,然后将输出与其他地址进行比较。 – nikobelia

回答

1

我刚才找出了问题所在。以下是我需要做的几件事情:

  1. 清单中的条目在我的〜/ .ssh/config文件的环回地址将指向放浪的insecure_private_key。一旦我这样做了,我就可以使用端口22和2222进行SSH(不使用vagrant ssh命令)。在这种情况下,我将主机命名为VagrantVM。

  2. 接下来的事情是我需要调整主机文件我用引用ansible编译:

    [vagrant] VagrantVM ansible_ssh_user=vagrant ansible_ssh_port=2222

一旦我做了这些调整,我跑vagrant provision和它的工作!

1

你能够连接到新创建的盒子vagrant ssh

什么是Ansible版本?你是使用VirtualBox作为虚拟机提供商,还是其他的?

也许尝试,如http://docs.vagrantup.com/v2/provisioning/ansible.html所述,删除ansible.inventory_path = "hosts"声明,因为您使用ansible.groups声明,因此Vagrant应生成自己的Ansible动态库存。

+0

如果我将它删除,生成的主机文件并且无法匹配主机。有没有办法配置vagrant生成的主机文件指向正确的IP而不是回送IP – ryekayo

+0

查看'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'文件以查看Vagrant生成的内容,然后发布在这里。 – ocean

+0

我更新了我的问题 – ryekayo