我有一個劇本,我試圖從私人回購(GIT)克隆到服務器。Git Clone的Ansible和Git權限被拒絕(publickey)
我已設置ssh轉發,當我ssh進入服務器並嘗試從同一個repo手動克隆時,它成功工作。但是,當我使用ansible將克隆到服務器的repo時,它會以「Permission Denied Public Key」權限失敗。
這是我的劇本deploy.yml
:
這是我ansible.cfg
的樣子:
[ssh_args]
ssh_args = -o FowardAgent=yes
我也能執行我的劇本中的所有其他任務(OS操作,安裝) 。
我曾嘗試:在服務器上
- 指定sshAgentForwarding標誌
ansible.cfg
使用(在同一目錄作爲劇本ansible.cfg):ssh_args = -o ForwardingAgent =是
- 使用
become: false
執行git克隆 運行
ansible -i devops/hosts webservers -a "ssh -T [email protected]"
返回:an_ip_address | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true }
這是我用來運行劇本命令: ansible-playbook devops/deploy.yml -i devops/hosts -vvvv
這是錯誤消息我得到:
fatal: [162.243.243.13]: FAILED! => {"changed": false, "cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "invocation": {"module_args": {"accept_hostkey": true, "bare": false, "clone":
true, "depth": null, "dest": "/var/www/aWebsite", "executable": null, "force": false, "key_file": null, "recursive": true, "reference": null, "refspec": null, "remote": "origin", "repo": "[email protected]:aUser/aRepo.git", "ssh_opts": null, "track_submodules": false, "update": true, "verify_commit": false, "version": "HEAD"}, "module_name": "git"}, "msg": "Permission denied (publickey).\r\nfatal: Could not r$ad from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "Permission denied (publickey).\r\nfatal: Could not read from remote r$pository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stdout": "", "stdout_lines": []}
有時,當你更新你的Mac,你的關鍵停止工作(至少對我來說)。我不得不'ssh-add -K〜/ .ssh/id_rsa'然後它工作。 – Will