# github deploy keys

**URL:** <https://forum.ansible.com/t/github-deploy-keys/11887>\
**Category:** Ansible Project\
**Created:** [September 12, 2012, 10:22pm UTC](https://forum.ansible.com/t/github-deploy-keys/11887 "2012-09-12T22:22:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ajax](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Ajax](https://forum.ansible.com/u/Ajax)\
**Post date:** [September 12, 2012, 10:22pm UTC](https://forum.ansible.com/t/github-deploy-keys/11887/1 "2012-09-12T22:22:02Z")

</div>

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](mailto: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”}

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 13, 2012, 12:39am UTC](https://forum.ansible.com/t/github-deploy-keys/11887/2 "2012-09-13T00:39:52Z")

</div>

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:
> 
> &nbsp;&nbsp;- name: make deploy key directory  
> &nbsp;&nbsp;&nbsp;&nbsp;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.

> &nbsp;&nbsp;- name: moving $project\_key to deploy\_keys  
> &nbsp;&nbsp;&nbsp;&nbsp;action: copy src=/deploy\_keys/$project'\_rsa'  
> dest=/home/$user/deploy\_keys/$project'\_rsa'
> 
> &nbsp;&nbsp;- name: adding ssh key to config file  
> &nbsp;&nbsp;&nbsp;&nbsp;action: shell echo IdentifyFile /home/$user/deploy\_keys/'$project'\_rsa
> 
> > > /home/$user/.ssh/config
> 
> &nbsp;&nbsp;- name: pulling/cloning $project  
> &nbsp;&nbsp;&nbsp;&nbsp;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?
