我尝试过的:
1) 将私钥从本地机器复制到服务器并用它克隆:
- name: clone repo
sudo: yes
git: repo={{ app_repo }} dest={{ app_repo_dir }} accept_hostkey=true key_file={{ssh_key}} version=master force=yes
但是它挂了。据我了解,此问题的发生是因为 key 有密码。
2) 在ansible.cfg中使用ForwardAgent
:
[ssh_connection]
ssh_args = -o ForwardAgent=yes
但是为了连接到服务器,我使用的不是标准的 ssh 22
端口。
如何在 Ansible 中为 git clone
任务设置 key 密码?或者使用 Ansible 克隆远程存储库的任何其他方法?
附言是的,我可以尝试从 key 中删除密码。但是安全方面...
最佳答案
~/.ssh/config :
主机 canada.host.xxxx
主机名 canada.host.xxxx
2233端口
用户 guest
IdentityFile ~/.ssh/id_rsa.special
2.
Copy private key from local machine to server and clone with it:
- name: clone repo sudo: yes git: repo={{ app_repo }} dest={{ app_repo_dir }} accept_hostkey=true key_file={{ssh_key}}
这是 Copy private key from local machine to server并用它克隆:
- name: Put artifact to target
sudo: yes
copy: src="{{ app_repo_dir }}" dest="{{ app_repo_dir }}"
- name: clone repo
sudo: yes
git: repo={{ app_repo }} dest={{ app_repo_dir }} accept_hostkey=true key_file={{ssh_key}} version=master force=yes
附言: 也许你应该使用 local_action ?
ansible-playbook -vvv 会告诉你问题所在
关于Git 克隆在 Ansible 中挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34822483/