【问题标题】:ansible in masterless mode git task fails while git clone works on remote server当 git clone 在远程服务器上工作时,无主模式下的 ansible git 任务失败
【发布时间】:2016-10-09 06:39:39
【问题描述】:

我正在使用 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

输出如下:

失败了! => {"changed": false, "cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "msg": "权限被拒绝 (公钥)。\r\n致命: 无法从远程读取 存储库。\n\n请确保您具有正确的访问权限 权限\n并且存储库存在。", "rc": 128, "stderr": "权限 被拒绝(公钥)。\r\n致命: 无法从远程读取 存储库。\n\n请确保您具有正确的访问权限 权限\n并且存储库存在。\n", "stdout": "", "stdout_lines": []}

我有一个类似的情况(ssh 和克隆适用于 CLI,但不适用于任务),我可以在远程服务器上克隆一个私有 git 存储库(使用 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 笔记本电脑到 Ubuntu 远程使用 ansible。版本是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克隆 git@github.com:ansible/ansible-examples.git /root/ansible-examples", “增量”:“0:00:00.693890”,“结束”:“2016-06-08 20:57:47.505574”, “失败”:真,“rc”:128,“开始”:“2016-06-08 20:57:46.811684”, "stderr": "正在克隆到 '/root/ansible-examples'...\n权限被拒绝 (公钥)。\r\n致命: 无法从远程读取 存储库。\n\n请确保您具有正确的访问权限 权限\n并且存储库存在。", "stdout": "", "stdout_lines": [], "警告": ["考虑使用 git 模块而不是运行 git"]}

【问题讨论】:

    标签: git github ssh ansible


    【解决方案1】:

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

    特别是ansible_useransible_connection

    【讨论】:

    • 也许这可能对其他人有所帮助:become: yes 的全球使用也是导致此类问题的常见陷阱。登录后直接切换到 root 用户,因此密钥转发不会坚持到新会话。
    • 这在我的 ssh git clone 随机开始失败后帮助了我。谢谢!
    猜你喜欢
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多