无主模式下的ansible git任务失败,而git clone在远程服务器

时间:2016-06-08 20:05:39

标签: git github ssh ansible

我正在使用Ansible克隆远程服务器上的存储库:

此命令适用于远程服务器:git clone git@github.com:ansible/ansible-examples.git

然而,这项任务失败了:

- name: clone git repo
      git: repo=git@github.com:ansible/ansible-examples.git 
           dest=/root/ansible-examples
           clone=yes

使用以下输出:

  

失败! => {"更改":false," cmd":" / usr / bin / git ls-remote'' -h refs / heads / HEAD","失败":true," msg":"权限被拒绝   (publickey)。\ r \ n \ nfatal:无法从远程读取   存储库。\ n \ n请确保您具有正确的访问权限   权利\ n和存储库存在。"," rc":128," stderr":"权限   否认(公钥)。\ r \ nfatal:无法从远程读取   存储库。\ n \ n请确保您具有正确的访问权限   版权所有。\ n"," stdout":""," stdout_lines":   []}

我有一个类似的情况(ssh和克隆适用于CLI而不是任务)有一个私有git repo,我可以在远程服务器上克隆(使用ssh转发),但失败并执行相同的任务。

我的ansible.cfg

中也有以下内容:
[defaults]
transport = ssh

# deprecation_warnings = False # In case it matters get the following [DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default).

[ssh_connection]
ssh_args = -o ForwardAgent=yes

注意:我在我的OSX笔记本电脑上使用ansible到Ubuntu遥控器。版本为ansible 2.1.0.0

如何使此任务克隆git存储库?

修改

不确定这意味着什么,但以下情况也不起作用(在控制台中也是如此):

- name: clone git repo
  shell:  if [[ ! -d /root/ansible-examples ]] ; then echo "CLONING" && git clone git@github.com:ansible/ansible-examples.git /root/ansible-examples ; else echo "already there" ; fi
  args:
    chdir: /root/
    creates: /root/ansible-examples/

另一次尝试:

shell: git clone git@github.com:ansible/ansible-examples.git /root/ansible-examples
  

失败! => {"改变":是的," cmd":" git clone   git@github.com:ansible / ansible-examples.git / root / ansible-examples",   " delta":" 0:00:00.693890"," end":" 2016-06-08 20:57:47.505574" ,   "失败":真实," rc":128,"开始":" 2016-06-08 20:57:46.811684",   " stderr":"克隆到' / root / ansible-examples' ... \ n许可被拒绝   (publickey)。\ r \ n \ nfatal:无法从远程读取   存储库。\ n \ n请确保您具有正确的访问权限   权利\ n和存储库存在。"," stdout":""," stdout_lines":[],   "警告":["考虑使用git模块而不是运行git"]}

1 个答案:

答案 0 :(得分:1)

事实证明我在CLI和ansible中没有相同的ssh用户。编辑主机文件修复了它:http://docs.ansible.com/ansible/intro_inventory.html

具体是ansible_useransible_connection

相关问题