If you use git module in Ansible to checkout a git repository over an
SSH transport and it gets stuck on the initial clone, the problem most likely
is that known_hosts file doesn’t exist or it doesn’t contain a host entry for
the server you want to clone from.
If you use verbose log level (-vvv option), the output will look something
like this:
Unlike other remote command execution frameworks like fabric, Ansible
doesn’t propagate prompts (which imo is good, since you really should automate
everything when using a deploy tool) and it simply get stuck and eventually
times out (getting stuck is definitely a bad UX, but that’s a different topic).
A lot of online tutorials simply suggest to disable strict host checking in the
SSH config. Unless you really know what you are doing, this is simply a bad idea
from a security perspective.
The correct thing to do is to add host key of the server you are cloning from
to the .ssh/known_hosts file.
Since you are using Ansible, you should also use it to manage known_hosts
file. Two approaches which show how to do this are displayed bellow.
1. Use Ansible to manage the whole known_hosts file (advised)
This approach simple copies known_hosts file from the local ansible files/
directory to a remote server.
2. Use Ansible to make sure some known_hosts entries are present
This approach assumes file already exists and makes sure specified host entries
are present.