ryekayo
ryekayo

Reputation: 2421

Ansible time out on Vagrant

I have been trying to use my YML file on the Vagrant box I built, which is CentOS. However, I am running into this timeout at ALL times:

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.

I have looked all over the Internet to figure out why it keeps Timing out and came up nothing, so I am asking StackOverFlow for any type of suggestions. Here is what my VagrantFile looks like:

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

And my host file I am using:

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

Does anyone have any reason why when I run vagrant provision, it times out on me?

Update: I have tried just using the default vagrant host file:

 Generated by Vagrant

default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222

Is there a way to change the default ansible_ssh_host from the loopback address to it's actual IP?

Upvotes: 1

Views: 1586

Answers (2)

ryekayo
ryekayo

Reputation: 2421

I just figured out what the problem was. Here are a few things I needed to do:

  1. List an Entry to the loopback address in my ~/.ssh/config file which will point to Vagrant's insecure_private_key. Once I did that, I was able to SSH using Port 22 and 2222 (without using vagrant ssh command). In this case, I named the Host: VagrantVM.

  2. Next thing was I needed to adjust the host file I was using to reference the ansible build:

    [vagrant] VagrantVM ansible_ssh_user=vagrant ansible_ssh_port=2222

Once I made these adjustments, I ran vagrant provision and it worked!

Upvotes: 1

ocean
ocean

Reputation: 1350

Are you able to connect to the newly-created box with vagrant ssh ?

What is your Ansible version? And are you using VirtualBox as the VM provider, or something else?

Maybe try, as described at http://docs.vagrantup.com/v2/provisioning/ansible.html, to remove the ansible.inventory_path = "hosts" statement, as Vagrant should be generating its own Ansible dynamic inventory because you're using the ansible.groups statement.

Upvotes: 1

Related Questions