在Vagrant上安排时间

时间:2015-09-03 01:36:19

标签: vagrant ansible

我一直在尝试在我构建的Vagrant盒子上使用我的YML文件,即CentOS。但是,我在所有时间都遇到此超时:

ryan@ryan-Galago-UltraPro:~/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.

我已经在互联网上查看了为什么它保持Timing out并且没有任何结果,所以我要求StackOverFlow提供任何类型的建议。这就是我的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时,是否有任何理由让我超时?

更新: 我试过使用默认的vagrant主机文件:

 Generated by Vagrant

default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222

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

2 个答案:

答案 0 :(得分:1)

您是否可以使用vagrant ssh连接到新创建的框?

你的Ansible版本是什么?您使用VirtualBox作为VM提供商还是其他什么?

正如http://docs.vagrantup.com/v2/provisioning/ansible.html所述,尝试删除ansible.inventory_path = "hosts"语句,因为您正在使用ansible.groups语句,因此Vagrant应生成自己的Ansible动态广告资源。

答案 1 :(得分:1)

我只知道问题所在。以下是我需要做的一些事情:

  1. 在〜/ .ssh / config文件中列出一个回送地址的条目,该文件将指向Vagrant的insecure_private_key。一旦我这样做,我就可以使用端口22和2222进行SSH(不使用vagrant ssh命令)。在这种情况下,我将Host命名为VagrantVM。

  2. 接下来我需要调整我用来引用ansible构建的主机文件:

    [vagrant] VagrantVM ansible_ssh_user=vagrant ansible_ssh_port=2222

  3. 一旦我做了这些调整,我就跑了vagrant provision它就有效了!