Ansible: svn: Network connection closed unexpectedly

From FVue
Jump to: navigation, search


Being logged in on a server - I'm trying to checkout a subversion repository on a client using an Ansible playbook:

subversion: repo=svn+ssh:// dest=/src/checkout
$ ansible-playbook example.yml

and I'm getting this error:

failed: [] => {"failed": true}
msg: svn: To better debug SSH connection problems, remove the -q option
from 'ssh' in the [tunnels] section of your Subversion configuration file.
svn: Network connection closed unexpectedly

This may clarify what's happening:

                     # +--------+     +--------+
                     # | SERVER |     | CLIENT |
                     # +--------+     +--------+
$ ansible-playbook   # |    +------>------+    |
                     # |        |     |        |
$ svn checkout       # |    +------<------+    |
                     # +--------+     +--------+


  • ansible-playbook-1.0

Solution 1. Forward ssh-agent

Ansible can connect to the workstation all right, but when trying to checkout the subversion repository - from within the workstation - the SSH connection fails. The solution is to forward the ssh-agent - including its unlocked keys - to the workstation.

1. Make sure your ssh configuration on the server has ForwardAgent enabled for the client (check .ssh/config or /etc/ssh/ssh_config):

    ForwardAgent yes

2. Tell Ansible to use openssh tools instead of paramiko to talk to managed nodes over SSH. Pass the flag --connection=ssh (or -c ssh) to any ansible command, or set the environment variable ANSIBLE_TRANSPORT=ssh .

ANSIBLE_SSH_ARGS= ansible-playbook example.yml --connection=ssh

Alternatively, I specified the connection in the Ansible playbook:

- hosts: example
  connection: ssh

And copied the examples/ansible.cfg to /etc/ansible/ansible.cfg (removing the ControlPersist ssh option, since Debian-6 ssh doesn't understand it). Now I can run just:

ansible-playbook example.yml

Solution 2. Client cannot connect to svn host

If the client cannot connect to the svn host, i.e. in our example, the same error message appears.

Test manually on the client if the svn host can be reached, e.g. via svn info svn+ssh://

Test manually on the client if the ssh host can be reached, e.g. via ssh . If not, the client might need an entry in ~/.ssh/config:

Host example



Different error:

fatal: [] => using -c ssh on certain older ssh versions
may not support ControlPersist, set ANSIBLE_SSH_ARGS="" 
(or ansible_ssh_args in the config file) before running again

In /etc/ansible/hosts I had specified an ip-address whereas in /etc/ssh/ssh_config I had specified the Host first:

Host foo
        ForwardAgent yes

Solution was to specify the Host (e.g. foo) in /etc/ansible/hosts AND do an export ANSIBLE_SSH_ARGS="" ?

Nope, now -c paramiko can't make the connection. Naming both hostname and ip-adress as Host in ssh_config now:

Host foo
        ForwardAgent yes
Command Line Examples And Next Steps — Ansible Documentation
Explanation where Ansible gets its configuration from


blog comments powered by Disqus