在服务器上,我可以成功运行以下命令:
ssh-agent bash -c 'ssh-add /path/key; git clone https://repo_path/repo_name.git'
存储库被克隆到“ repo_name”
但是,当我在本地计算机上运行以下ansible(2.2)脚本时,克隆任务会无限期停止
- name: clone or pull latest web app code
git: repo=https://repo_path/repo_name.git dest=/home/user/repo_name
key_file=/path/key
accept_hostkey=yes
force=yes
克隆任务之前的其他任务都可以正常工作(apt更新,库安装等)
我正在使用以下方法检查路径是否正确,并且看起来还可以:
- debug:
msg: "about to clone code {{ code_repository }} to {{ base_dir }}"
有什么想法吗?
答案 0 :(得分:4)
注意:ssh-add /path/key
和git clone https://repo_path/repo_name.git
与彼此无关。
ssh-add /path/key
用于在ssh-agent中添加受密码保护的私密SSH密钥,以便在SSH URL需要时可以缓存所述密码。
https://repo_path/...
是HTTPS URL,这意味着它不需要SSH密钥。完全没有。
ansible git module确实提到:
accept_hostkey
如果是,请确保作为ssh选项显示“
-o StrictHostKeyChecking=no
”。
同样,该URL是HTTPS,因此不需要。
尝试删除key-file
和accept_hostkey
,以查看HTTPS克隆是否可以继续进行。
对于SSH URL,您需要确保:
~git/.ssh/authorized_keys
中),~/.ssh/known_hosts
已正确更新,as I have seen yesterday带有“ SSH connection problem with “Host key verification failed…” error”。