github deploy keys

I’m having trouble using Ansible to clone a private repo on github on a remote node using a deploy key for authentication. Ultimately I want to move the private key over the to the remote node, add the location of the key to the .ssh/config file, and then use the Ansible git module to pull or clone a repo. When I attempt to use the git module I get a “permission denied” error. I’ve included the relevant portions of the code below. Can someone give me some insights how how I should be handling this problem?

Thanks!

Tasks:

  • name: make deploy key directory
    action: command mkdir deploy_keys

  • name: moving $project_key to deploy_keys
    action: copy src=/deploy_keys/$project’_rsa’ dest=/home/$user/deploy_keys/$project’_rsa’

  • name: adding ssh key to config file
    action: shell echo IdentifyFile /home/$user/deploy_keys/‘$project’_rsa >> /home/$user/.ssh/config

  • name: pulling/cloning $project
    action: git repo=git@github.com:repo_name/‘$project’.git dest=/home/$user/$project

Error:
{“failed”: true, “msg”: “Permission denied (publickey).\r\nfatal: The remote end hung up unexpectedly\n”}

Hi Chris, not sure I have much insight, but some ideas, included below:

I'm having trouble using Ansible to clone a private repo on github on a
remote node using a deploy key for authentication. Ultimately I want to move
the private key over the to the remote node, add the location of the key to
the .ssh/config file, and then use the Ansible git module to pull or clone a
repo. When I attempt to use the git module I get a "permission denied"
error. I've included the relevant portions of the code below. Can someone
give me some insights how how I should be handling this problem?

Tasks:

  - name: make deploy key directory
    action: command mkdir deploy_keys

You probably want to have a "creates=deploy_keys" added to your
command action above or use the file module like so:

file path=/some/path owner=foo group=foo state=directory

otherwise everytime you run this it will do another 'mkdir'. Not that
big of an issue in this case but probably better not to.

  - name: moving $project_key to deploy_keys
    action: copy src=/deploy_keys/$project'_rsa'
dest=/home/$user/deploy_keys/$project'_rsa'

  - name: adding ssh key to config file
    action: shell echo IdentifyFile /home/$user/deploy_keys/'$project'_rsa

/home/$user/.ssh/config

  - name: pulling/cloning $project
    action: git repo=git@github.com:repo_name/'$project'.git
dest=/home/$user/$project

Error:
{"failed": true, "msg": "Permission denied (publickey).\r\nfatal: The remote
end hung up unexpectedly\n"}

Looks like the git command might be using the wrong public key. Does
it work when you call the git command manually? Any errors in the
logs?