简体   繁体   中英

Ansible Playbook: Permission denied (publickey), could not read from remote repository

I am running an ansible playbook to pull a repository from github. I have generated my ssh key and added the key to my github profile.

My play is:

- name: Clone git repository
  git: >
    dest=/var/www/PlantMan/
    repo=git@github.com:RockyMountainCollege/PlantMan.git
    update=no

Results in the following error:

fatal: [web1]: FAILED! => {"changed": false, "cmd": "/usr/bin/git clone --origin origin '' /var/www/PlantMan", "msg": "Cloning into '/var/www/PlantMan'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.", "rc": 128, "stderr": "Cloning into '/var/www/PlantMan'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.", "stderr_lines": ["Cloning into '/var/www/PlantMan'...", "Permission denied (publickey).", 
"fatal: Could not read from remote repository.", "", 
"Please make sure you have the correct access rights", "and the repository exists."], "stdout": "", "stdout_lines": []}

Trying to debug I ssh into the web node and ran

ssh -vT git@github.com

with the result:

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: Connection established.
debug1: identity file /home/vagrant/.ssh/id_rsa type 1
debug1: identity file /home/vagrant/.ssh/id_rsa-cert type -1
debug1: identity file /home/vagrant/.ssh/id_dsa type -1
debug1: identity file /home/vagrant/.ssh/id_dsa-cert type -1
debug1: identity file /home/vagrant/.ssh/id_ecdsa type -1
debug1: identity file /home/vagrant/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/vagrant/.ssh/id_ed25519 type -1
debug1: identity file /home/vagrant/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.10
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/vagrant/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/vagrant/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.112]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi {username}! You've successfully authenticated, but GitHub does not provide 
shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3312, received 1792 bytes, in 0.1 seconds
Bytes per second: sent 25624.1, received 13864.3
debug1: Exit status 1

It seems that the web node can ssh to github but when I run the play it throws an access denied.

Set key_file if your repo is private and your preferred method is ssh .

- name: Clone git repository
  git: >
    dest=/var/www/PlantMan/
    repo=ssh://git@github.com/RockyMountainCollege/PlantMan.git
    key_file=/home/vagrant/.ssh/id_rsa
    update=no

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM