Gathering facts takes forever when host machine is offline

When I'm trying to develop my play books while offline on my laptop (using vagrant for my Ansible provisioned server) I'm seeing really long hangs on the GATHERING FACTS task (as in the order of 3-5 minutes). After it eventually times out (best guess) it proceeds as normal and everything works properly.

Any idea if this is expected behavior for Ansible? I need some of the variables from the setup methods so I can't just turn off the fact gathering unfortunately. Just curious as to what might be trying to call "home" or "out" that could cause such a long hang when offline...

Thanks,

Steven

You should have a pretty quick failure to connect if the machine is not running.

Sorry, both the control machine (my MacBook Air) and the Ansible remote node (my vagrant VM) are running perfectly fine (I can ssh into the Vagrant VM without a problem, and Ansible eventually does run through the play book after the 3-5 minutes pause on gathering facts completes. The only difference from when there's a delay vs. not is that my MacBook Air is offline for wifi.

I'd paste the debug output, but I'm offline at the moment :stuck_out_tongue: I'll gladly paste it later if desired.

-Steven

This sounds like a DNS issue to me.

May be you could use ansible_ssh_host for your VM in your host file ou
fill your /etc/hosts with the machine name and it's IP.

M

root@llamacube:/tmp# time ansible doesnotexist.example.com -m ping -i “doesnotexist.example.com,”
doesnotexist.example.com | FAILED => failed to transfer file to /ping:

ssh: Could not resolve hostname doesnotexist.example.com: Name or service not known
Couldn’t read packet: Connection reset by peer

real 0m1.107s
user 0m0.060s
sys 0m0.076s

FWIW, I’d prefer it if the error message didn’t include the “failed to transfer file” in this case. We should upgrade that part :slight_smile:

I would add" UseDNS No" in your vagrant’s sshd_config, it is not very useful and it tends to slow things down a lot when the client is not in DNS.

$ time ansible-playbook provisioning/site.yml -i provisioning/hosts/vagrant -u vagrant -s -v

PLAY [Initialize all SUPPORT servers] *****************************************

GATHERING FACTS ***************************************************************
ok: [33.33.33.10]

…[play books & tasks omitted]…

33.33.33.10 : ok=26 changed=1 unreachable=0 failed=1

real 5m31.437s
user 0m1.434s
sys 0m1.078s

Brian: I checked the sshd_config and it already has the “UseDNS no” line set via vagrant’s tweaks itself apparently.

Overall there isn’t an error that’s ever thrown, just a long delay between the “GATHERING FACTS” start time and end time before the play books run as expected…

Thanks for any other ideas,

Steven

Steven,

Could you compare the timings for :

time ansible <only one host> -m ping -i provisioning/hosts/vagrant -u
vagrant -s -v

and

time ansible <same host> -m setup -i provisioning/hosts/vagrant -u
vagrant -s -v

While you're doing that, it could be great to have a tcpdump running on
the vagrant machine in some other terminal, tracking network traffic :

vagrant ssh <host> "tcpdump -nviany port not 22"

Your problem really sounds like a netwprk time out issue on the vagrant
host (with DNS reverse lookup being the ususal suspect). However, I've
skimmed through setup module code and it doesn't do any DNS lookup
AFAIK... So it might be something else.

M

I realise this is an old thread but this does seem to be a reverse lookup issue. I am seeing this using one Vagrant VM as an Ansible server and another as an Ansible target and connecting to it via an SSH port forwarded to the Windows host server (not sure how much of this is relevant). Anyhow, it is a 60 second timeout on my set up and I resolved it by adding the target host name to /etc/hosts as an alias to 127.0.0.1.

useDNS=no in sshd_config, not really useful except to make things slower.