How to correctly authenticate git user with SSH key

1,177 views
Skip to first unread message

9dev...@gmail.com

unread,
Jul 20, 2014, 6:55:14 AM7/20/14
to ansible...@googlegroups.com
I want to pull code from Bitbucket.org

- copy: src=path/to/mykey.pub dest=/home/{{ username }}/.ssh/mykey.pub
  sudo
: false
   
- copy: src=path/to/mykey dest=/home/{{ username }}/.ssh/mykey mode=0600
  sudo
: false

- copy: src=path/to/known_hosts dest=/home/{{ username }}/.ssh/known_hosts
  sudo
: false

- authorized_key: user={{ username }} key="{{ lookup('file', '/home/{{username}}/.ssh/mykey.pub') }}"

- git: repo={{ project_repo }} dest={{ project_code }} version={{ branch }} accept_hostkey=true key_file="{{ lookup('file', '/home/{{ username }}/.ssh/mykey.pub') }}"

After running this playbook I get:

...
"cmd": "/usr/bin/git ls-remote g...@bitbucket.org:/myusername/mypro.git -h refs/heads/develop", "failed": true
...
stderr
: Permission denied (publickey).
fatal
: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

NOTICE: While using bash, I can execute the "cmd" command without errors (even without sudo). My user logs in and connect to the repo. I do not understand why ansible is not able to repeat it.

mvermaes

unread,
Jul 20, 2014, 8:19:10 AM7/20/14
to ansible...@googlegroups.com
Couple of things to check:
- Can you run the git command with 'sudo: false'? See here for why: https://help.github.com/articles/error-permission-denied-publickey#sudo-or-sudont
- If you need to run git with sudo, and that's why you have specified key_file=..., I think you want to use your private key (mykey), rather than your public key (mykey.pub).

Hope it helps.
Reply all
Reply to author
Forward
0 new messages