2014-01-29 60 views
31

我已经设置了everyhing我可以找到,但仍克隆从GitHub repo挂起配置过程。Git通过SSH在Ansible挂起,事件虽然ssh代理转发设置

我有:在known_hosts中

  • 服务器
  • 的.ssh/config中

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

  • 公共密钥是通过在authorized_keys
  • 命令运行作为vagrant用户
  • 的打法是:

    - name: Checkout from git 
        git: [email protected]:username/repositoryname.git dest=/srv/website 
    
+6

请确保您没有使用'sudo'运行此任务,因为它会中断代理转发。 –

+0

@techtonik即使转发设置为root用户? – cvsguimaraes

+0

@cvsguimaraes转发是从您的'ssh-agent'端口到远程SSH端口的连锁,并且通过'sudo'打破这个链条,除非您解决这个问题。请参阅http://stackoverflow.com/a/24134109/239247 –

回答

14

,我想分享的是为我工作的回答:

https://groups.google.com/forum/#!msg/ansible-project/u6o-sWynMjo/69UwJfJPq7cJ - 从Ansible谷歌

集团

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

如:用于

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

见手册SSH-添加运行的代理。

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

7

这对我的作品

- 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 
+14

不需要,因为git ansible模块有一个标志accept_hostkey来确保它。只需打开它。 – kaji

+1

Ansible用于维护/ etc/ssh/ssh_known_hosts文件的模块https://github.com/bfmartin/ansible-sshknownhosts – jitter

60

只是对tillda的答案扩大,这个配置可以放置在一个ansible.cfg文件旁边的剧本。例如:

ansible.cfg

[defaults] 
transport = ssh 

[ssh_connection] 
ssh_args = -o ForwardAgent=yes 

我会说这是好做,除设置为环境变量,如将其放置在conf文件既更声明,也将减少您可能正在与一个项目合作的其他人所需的步骤。

的conf文件: http://docs.ansible.com/intro_configuration.html#the-ansible-configuration-file

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

+0

我同意。谢谢你。 –

+0

这为我工作。谢谢! – bcherny

+1

对我不起作用仍然卡住 – holms

0

我有一个错误:

bitbucket.org具有未知hostkey。设置accept_hostkey为True或hostkey运行git的模块

我只好一个accept_hostkey参数添加到我的git模块命令之前手动添加:

剧本:

tasks: 
    - name: clone 
     git: [email protected]:robusta-code/xyz.git 
      dest=/app 
      accept_hostkey=yes 

ansible。 cfg

[ssh_connection] 
ssh_args = -o ForwardAgent=yes 
1

将以下参数添加到ansible.cfg中:

[defaults] 
sudo_flags=-HE 
1

在我的情况下,问题是存储库字符串。我有一个私人到位桶仓库设置为:

混帐@ TSRS ...

,但它应该是:

SSH:// @混帐TSRS ...

注意前缀“ssh”的细微缺失。奇怪的部分是,如果我克隆一个没有“ssh”的github仓库,它工作正常!