How to prevent git clone timeouts in playbook?

I have a task in my Ansible playbook that uses the git module to clone my Git repository which is hosted on 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]: 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.

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

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

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.