繁体   English   中英

在Ansible中通过SSH进行GIT挂起,即使设置了ssh-agent转发也是如此

[英]GIT over SSH in Ansible hangs, eventhough ssh-agent forwarding is set up

我已经设置了我能找到的每一个,但仍然从GitHub克隆一个repo挂起了配置过程。

我有:

  • known_hosts中的服务器
  • 的.ssh /配置

     Host github.com ForwardAgent yes StrictHostKeyChecking no 
  • 复制私钥

  • 公钥在authorized_keys中
  • 该命令作为vagrant用户运行
  • 该剧是:

     - name: Checkout from git git: repo=git@github.com:username/repositoryname.git dest=/srv/website 

只是为了扩展到fifda的答案,该配置可以放在你的剧本旁边的ansible.cfg文件中。 例如:

ansible.cfg

[defaults]
transport = ssh

[ssh_connection]
ssh_args = -o ForwardAgent=yes

我认为这样做比设置为env变量更好,因为将它放在conf文件中更具说明性,并且还将最小化您可能正在使用项目的其他人所需的步骤。

Conf docs: http//docs.ansible.com/intro_configuration.html#the-ansible-configuration-file

配置文件示例: https//raw.github.com/ansible/ansible/devel/examples/ansible.cfg

我想分享对我有用的答案:

https://groups.google.com/forum/#!msg/ansible-project/u6o-sWynMjo/69UwJfJPq7cJ - 来自Ansible Google Group

对于ansible,ssh-add首先在主机中加载ssh密钥。 然后使用“ssh”作为连接类型并启用转发。

如:

 $ ssh-add $ export ANSIBLE_TRANSPORT="ssh" $ export ANSIBLE_SSH_ARGS="-o ForwardAgent=yes" 

有关运行代理的信息,请参阅ssh-add手册。

ssh-args的Ansible文档是http://docs.ansible.com/intro_configuration.html#ssh-args

这对我有用

- name: ensure known hosts
  shell: touch ~/.ssh/known_hosts
- name: remove github.com from known host
  shell: ssh-keygen -R github.com
  # >> instead of > to keep existing known_hosts file
- name: ensure github.com in known host
  shell: ssh-keyscan -H github.com >> ~/.ssh/known_hosts

添加到ansible.cfg以下参数:

[defaults]
sudo_flags=-HE

就我而言,问题是存储库字符串。 我有一个bitbucket私有存储库设置为:

Git的@ TSRS ...

但它应该是:

ssh :// git @tsrs ...

注意前缀“ssh”的微妙缺失。 奇怪的是,如果我克隆一个没有“ssh”的github存储库,它运行正常!

我有一个错误:

bitbucket.org有一个未知的主机密钥。 将accept_hostkey设置为True或在运行git模块之前手动添加hostkey

我必须在我的git模块命令中添加一个accept_hostkey参数:

剧本:

tasks:
    - name: clone
      git: repo=git@bitbucket.org:robusta-code/xyz.git
           dest=/app
           accept_hostkey=yes

ansible.cfg

[ssh_connection]
ssh_args = -o ForwardAgent=yes

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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