繁体   English   中英

为什么在 Ansible 中克隆 repo 失败但手动工作?

[英]Why is cloning a repo failing in Ansible but works manually?

作为更大剧本的一部分,我尝试在 Ansible 任务中克隆一个 repo,但它失败了git@github.com: Permission denied (publickey). . 手动执行相同的操作。 怎么了?

我的剧本的最小示例:

---
- hosts: all
  tasks:
    - name: Ensure dotfiles repository is cloned locally.
      git:
        repo: "git@github.com:geerlingguy/dotfiles.git"
        dest: "~/devops/macsetup/dotfiles"
        key_file: /Users/myUser/.ssh/id_ed25519
        version: "main"
        accept_hostkey: true
      become: false

库存文件:

[all]
127.0.0.1 ansible_connection=local

ansible.cfg:

[defaults]
nocows = true
roles_path = ./roles
inventory = inventory
become = true
stdout_callback = yaml
log_path = ~/Desktop/ansibleLog_test.txt

结果:

TASK [Ensure dotfiles repository is cloned locally.] ***************************************************************************************
The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/var/folders/3v/qk0n7z693jv2pz23cy99q7_m0000gn/T/ansible_git_payload_TeGqRk/ansible_git_payload.zip/ansible/modules/git.py", line 499, in clone
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
fatal: [127.0.0.1]: FAILED! => changed=false 
  cmd: /usr/bin/git ls-remote '' -h refs/heads/main
  invocation:
    module_args:
      accept_hostkey: true
      archive: null
      archive_prefix: null
      bare: false
      clone: true
      depth: null
      dest: /Users/myUser/devops/macsetup/dotfiles
      executable: null
      force: false
      gpg_whitelist: []
      key_file: /Users/myUser/.ssh/id_ed25519
      recursive: true
      reference: null
      refspec: null
      remote: origin
      repo: git@github.com:geerlingguy/dotfiles.git
      separate_git_dir: null
      single_branch: false
      ssh_opts: null
      track_submodules: false
      umask: null
      update: true
      verify_commit: false
      version: main
  msg: ''
  rc: 128
  stderr: |-
    git@github.com: Permission denied (publickey).
    fatal: Could not read from remote repository.
  
    Please make sure you have the correct access rights
    and the repository exists.
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>
PLAY RECAP ***************************************************************************************
127.0.0.1                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

我意识到 ansible 实际上正在运行git ls-remote '' -h refs/heads/main ls-remote文档并不太冗长。

在没有更多信息的情况下,真的不可能回答这个问题,但作为解决此类问题的一般规则 - 除了您已经完成的工作之外 - 这里有一些提示:

  • 运行-vvvv时打开调试(例如,命令行上的-vvvv ) - 这通常可以帮助您查看额外信息,例如正在使用的用户/连接详细信息
  • 添加一些运行您在目标机器上手动尝试过的命令行任务的预任务,并检查您是否看到相同的结果(例如command: whoamicommand: ls -l /Users/myUser/.ssh/id_ed25519
  • 在目标上手动运行与通过 ansible 运行 - 通常情况下,手动登录是通过 dotfiles 设置 shell 环境,这可能与无头 ansible 登录不同

在后一种情况下,它依赖于目标,但这里有一些 bash 示例: Not possible to source .bashrc with Ansible

暂无
暂无

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

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