Update 2: Well, what can I tell you, it works again. Literally the only thing I did was exchange my old and slow hard drive with an SSD I still had lying around. Other than that I followed the exact same setup procedure (clean windows install, same install medium, same software versions, same software in generall). No idea how this could effect anything. I never really believed it to be a timeout issue because, as I said, it used to work on this machine with this setup. Maybe a Windows update changed some networking behaviour. I don't know. Anyways, I still have the old hard drive lying around, so if anybody has some interesing ideas on how to fix this, I might give it a shot. However, now that I have a working laptop it's not my top priority any more.

Update 1: I can confirm that this works on my other dev machine, which is considerably more powerfull but otherwhise has the exact same setup (software versions, configs, etc.). This is especially strange considering that my problem machine is a clean install.

The Goal:

I'm using Vagrant to set up a web development environment on my Windows 10 machines.

Vagrant (on Windows) is used to spin up Virtualbox VMs (also on Windows) to host a Debian Linux. I use Windows Subsystem for Linux (Debian Distro) to run Ansible in order to configure these VMs and my production server (which is a remote machine running - you guessed it - Debian).

The Problem:

Ansible will not connect to the Virtualbox VMs. It just hangs on the first connection attempt without any errors. I have to abort it with Ctrl+C.

Here is where it gets strange: I can connect to the VMs just fine with Putty from Windows and SSH from WSL, so I know the VM is reachable and SSH works. Ansible can also reach my remote server just fine, so Ansible itself is not broken either. The problem occurs only between Ansible and the local VMs and only on this machine.

This very same setup (same git repo, same config files, same software versions) actually works fine on my other machine and a while ago it used to work on this machine as well. So I know that it works in theory. I just can't for the life of me figure out what's different between these machines or what I changed that caused it to break.

I've spent days searching the internet and trying everything I could find or think of. By now I have even completely re-installed Windows and the whole dev environment with it, but no luck, the error stays. I'm quite desperate because the way it is right now, this machine is unusable as a development machine.

Background Info:

I run Ansible like this (for example):

 ansible appserver -i environments/development --ask-vault-pass -k -e "ansible_user=vagrant" -m ping

after which ansible asks for the SSH password, vault password, and then nothing happens.

When I abort with Ctrl+C I get the following error in /var/log/auth.log on the VM:

sshd[1343]: Connection closed by port 51481 [preauth]

That IP address is the one from the host-only network of the Virtualbox machine as seen in the network config dialog of Virtualbox, not the IP address of the VM itself. The sshd pid is different every time.

When I run the ping module in a playbook, I get three of those lines right away (with different ports on each line) and another one of those after I hit Ctrl+C.

This is my ansible.cfg (in my project dir, the one in /etc is untouched):

force_handlers = True
hash_behaviour = merge

The Ansible inventory is pretty unspectacular (just the IP)

When I run the above ansible command with -vvvv I get the following:

ansible 2.7.6
config file = /mnt/d/Source/main_server/ansible/ansible.cfg
configured module search path = [u'/home/my_user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516]
Using /mnt/d/Source/main_server/ansible/ansible.cfg as config file
SSH password:
Vault password:
setting up inventory plugins
/mnt/d/Source/main_server/ansible/environments/development did not meet host_list requirements, check plugin documentation if this is unexpected
Parsed /mnt/d/Source/main_server/ansible/environments/development inventory source with ini plugin
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/minimal.pyc
META: ran handlers
Trying secret <ansible.parsing.vault.PromptVaultSecret object at 0x7f8a35652610> for vault_id=default 
<> SSH: EXEC sshpass -d9 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/sseeland/.ansible/cp/d986014952 '/bin/sh -c '"'"'echo ~vagrant && sleep 0'"'"''

And then only silence until I hit Ctrl+C.

This is my Vagrant file:

Vagrant.configure("2") do |config|
    config.vm.box = "debian/stretch64"
    config.vm.boot_timeout = 120
    config.vm.synced_folder ".", "/vagrant", type: "virtualbox"

    config.vm.provider "virtualbox" do |v|
        v.customize [ "modifyvm", :id, "--nictype1", "virtio" ]

    config.ssh.forward_agent = true

    config.vm.define "dev" do |dev|
        # Setting up private_network to have reliable ip and port from host
        dev.vm.network :private_network, ip: "", nic_type: "virtio"

        # mount source code into machine
        dev.vm.synced_folder "../../svenseeland_site/", "/svenseeland_site/", type: "virtualbox"

    config.vm.define "staging" do |staging|
        # Setting up private_network to have reliable ip and port from host
        staging.vm.network :private_network, ip: "", nic_type: "virtio"

    # set timezone
    config.vm.provision "shell", name: "set timezone", inline: <<-SHELL
        sudo rm /etc/localtime
        sudo ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime

    # add vagrant user to SSH group
    config.vm.provision "shell", name: "add vagrant user to SSH group", inline: <<-SHELL
        usermod -a -G ssh vagrant

    # set root password
    config.vm.provision "shell", name: "set root password", inline: <<-SHELL
        echo -e "vagrant\nvagrant" | sudo passwd

    # enable passwordless root login to mirror the production server setup and open the door for Ansible
    config.vm.provision "shell", name: "enable keyless ssh login", inline: <<-SHELL
        sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
        echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
        service ssh restart

Some of that setup regarding users and passwords for SSH is to prepare it for management by Ansible and to be consistent with the init state of my production server as it is provided by the hoster.

Software Versions:

  • Vagrant 2.2.3
  • Virtualbox 6.0.4
  • Ansible 2.7.6
  • Debian 9.7 (official vagrant box)
  • Windows 10 version 1809, Build 17763.253
  • WSL/Debian is up to date (apt-get dist-upgrade)

Let me know if you need any more info.


Basic setup:

  • Set up Host-Only network between host and guest OS (further details in this answer).
  • Configure SSH key pair properly and SSH from WSL into that VM with Host-Only IP address.
  • Install ansible in WSL distribution, check ansible --version if it is properly installed.

Detailed explanation of every basic steps are omitted because OP has done 99% of the work.


  • In WSL distribution, add Host-Only IP address in /etc/ansible/hosts file. Or add the VM settings in inventory file as mentioned in this answer.
  • To use Ansible with SSH password install sshpass in WSL.
  • Run this command to check if Ansible working ansible all --user=usename --ask-pass --module-name=ping. See Ansible Docs for further details about command options.
  • Thanks for the answer, I hope it will be helpful for people who see this in the future. As you said, I already did almost all of this and as I said, this setup is working on my other dev machine. So the basic idea of how to do it was not the problem. I wonder, however, why would I install Ansible on the VM? One of the selling points of Ansible is that the target machine doesn't need anything but Python and SSH (and a passwordless sudo user).
    – MadMonkey
    Jan 31 '19 at 7:40
  • "why would I install Ansible on the VM?" -- That will not require. My mistake, I'll edit the answer. "a passwordless sudo user" -- Hmm, one may do that but isn't "with password" more secure? Please forgive, I've no idea or no experience of IT environment, just a student :)
    – Biswapriyo
    Jan 31 '19 at 8:29
  • Passwordless sudo is considered best practice. You just have to be sure that the Ansible user is well secured. Only allow key based ssh login, never run any network-facing processes as the Ansible user, etc. However, your comment prompted me to do some reading and it turns out you actually can specify sudo passwords, even individually per server and secured by vault. I might try that.
    – MadMonkey
    Jan 31 '19 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.