{{tag>git ansible ssh}} ====== Clone remote repository with ansible git module using ssh key ====== You can use your ssh agent to forward the keys to the remote server, however when running ansible on one remote host and deploying to another, for example when triggering ansible from a Rundeck job easiest is to copy the private key file on the remote host. e.g. in the playbook add task ... - name: Ensure ssh deploy key is present on the server. copy: content: "{{ deploy_private_key }}" dest: /tmp/deploy_key mode: 0600 ... - name: 'Delete private key' file: path: "/tmp/deploy_key" state: absent tags: deploy_artifact ====== Tested on ====== * Debian 10 * Bitbucket cloud ====== See also ====== * [[wiki:git_pull_via_ssh_public_key|git pull via ssh public key]] ====== References ====== * https://www.jeffgeerling.com/blog/2018/cloning-private-github-repositories-ansible-on-remote-server-through-ssh