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.
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).
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.
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: Connection closed by 192.168.33.1 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):
[defaults] 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 <192.168.33.10> ESTABLISH SSH CONNECTION FOR USER: vagrant <192.168.33.10> 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 192.168.33.10 '/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" ] end 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: "192.168.33.10", nic_type: "virtio" # mount source code into machine dev.vm.synced_folder "../../svenseeland_site/", "/svenseeland_site/", type: "virtualbox" end config.vm.define "staging" do |staging| # Setting up private_network to have reliable ip and port from host staging.vm.network :private_network, ip: "192.168.33.11", nic_type: "virtio" end # 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 SHELL # add vagrant user to SSH group config.vm.provision "shell", name: "add vagrant user to SSH group", inline: <<-SHELL usermod -a -G ssh vagrant SHELL # set root password config.vm.provision "shell", name: "set root password", inline: <<-SHELL echo -e "vagrant\nvagrant" | sudo passwd SHELL # 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 SHELL end
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.
- 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.