# How to prevent git clone timeouts in playbook?

**URL:** <https://forum.ansible.com/t/how-to-prevent-git-clone-timeouts-in-playbook/23580>\
**Category:** Ansible Project\
**Created:** [January 27, 2017, 7:37pm UTC](https://forum.ansible.com/t/how-to-prevent-git-clone-timeouts-in-playbook/23580 "2017-01-27T19:37:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [January 27, 2017, 7:37pm UTC](https://forum.ansible.com/t/how-to-prevent-git-clone-timeouts-in-playbook/23580/1 "2017-01-27T19:37:51Z")

</div>

I have a task in my Ansible playbook that uses the git module to clone my Git repository which is hosted on [bitbucket.com](http://bitbucket.com) to my Linode-hosted web server. The playbook is run from my local laptop. My problem is that this task seems to timeout quit frequently. When it does, I’ll get the following error:

fatal: [[web02.example.com](http://web02.example.com)]: FAILED! =\> {… “msg”: “Cloning into ‘/srv/http/example.com/repo’…\nHost key verification failed.\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists”, “rc” 128,…}

I’m pretty certain this is a timeout error because I haven’t changed my SSH keys, the access rights are correct, and the repository does exist. Furthermore, if I run the entire playbook again it will sometimes succeed and other times I’ll have to re-run it a couple of times before it succeeds.

Here’s the task:

# webservers.yml

- name: check out dev version of django project repo  
git: \>  
repo={{ repo\_url }}  
version=dev  
dest={{ repo\_path }}  
accept\_hostkey=yes  
become: true  
become\_user: “{{ me }}”

Here’s my config file:

# ansible.cfg

[defaults]  
inventory = inventories/development  
remote\_user = smith  
roles\_path = $HOME/playbooks/roles:$HOME/playbooks/community/roles  
vault\_password\_file = vault\_pass  
retry\_files\_enabled = False  
retry\_files\_save\_path = “/tmp”  
host\_key\_checking = False

# Try to prevent git clone from timing out

ssh\_args = -o ControlPersist=360s

[ssh\_connection]  
pipelining = True

I read that setting ssh\_args as shown above might prevent this problem but it doesn’t seem to help. Is there something else I can do to prevent these timeouts so that I don’t have to keep re-running my playbook to get my repo cloned? Thanks.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [January 30, 2017, 11:33am UTC](https://forum.ansible.com/t/how-to-prevent-git-clone-timeouts-in-playbook/23580/2 "2017-01-30T11:33:40Z")

</div>

Well you could use ansible blocks to retry if the first attemp fails

[http://docs.ansible.com/ansible/playbooks\_blocks.html](http://docs.ansible.com/ansible/playbooks_blocks.html)

I would be tempted to change things around somewhat and spin up an ansible instance ‘near’ the other machines you want to manage (i.e. same datacenter/cloud/network - you get the idea), then you reduce likelihood of timeouts in the first place.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [January 30, 2017, 5:22pm UTC](https://forum.ansible.com/t/how-to-prevent-git-clone-timeouts-in-playbook/23580/3 "2017-01-30T17:22:38Z")

</div>

Thanks Jon. I was thinking the same thing, to set up a small server near my other machines solely for build purposes in order to minimize latency. I’ll also take a look at blocks.
