尝试直接从 Ansible 克隆时出现 Git fatal error

标签 git github deployment ansible clone

我正在使用 ansible (Trellis) 来部署我的项目。

我在 github 上有一个 repo。

这是我的ansible代码

- name: UPDATE - Clone project files
  become: yes
  # become_user: "{{ project.user.name | default(ansible_web_user) }}"
  git:
    repo: "{{ project.git.ssh }}"
    dest: "{{ project_root }}/shared/source"
    version: "{{ project.git.branch | default('master') }}"
    accept_hostkey: "{{ project.git.accept_hostkey | default(repo_accept_hostkey | default(true)) }}"
    force: yes
    # key_file: "/root/.ssh/id_rsa.pub"
  ignore_errors: false
  no_log: false
  register: git_clone

几天来这个错误没有明显的原因出现,没有任何改变

FAILED! => {"changed": false, "cmd": "/usr/bin/git ls-remote origin -h refs/heads/master", "msg": "fatal: 'origin' does not appear to be a git repository\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "fatal: 'origin' does not appear to be a git repository\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stderr_lines": ["fatal: 'origin' does not appear to be a git repository", "fatal: Could not read from remote repository.", "", "Please make sure you have the correct access rights", "and the repository exists."], "stdout": "", "stdout_lines": []}

我已经尝试了几种解决方案,甚至删除了 forwardAgent 并强制 key_file 直接进入 git 调用。它仍然返回错误。

但是如果我通过 ssh 连接到目标机器并尝试执行 git clone .... 一切正常。

我不明白这可能是什么问题。

最佳答案

添加

- name: UPDATE - Safe Directory
  command: git config --global --add safe.directory {{ project_root }}/shared/source
  check_mode: no

和编辑

- name: UPDATE - Clone project files
  # become: yes
  # become_user: "{{ project.user.name | default(ansible_web_user) }}"
  git:
    repo: "{{ project.git.ssh }}"
    dest: "{{ project_root }}/shared/source"
    version: "{{ project.git.branch | default('master') }}"
    accept_hostkey: "{{ project.git.accept_hostkey | default(repo_accept_hostkey | default(true)) }}"
    force: yes
    key_file: "/root/.ssh/id_rsa"
    update: no
  ignore_errors: false
  no_log: false
  register: git_clone

我解决了问题;)

关于尝试直接从 Ansible 克隆时出现 Git fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72490484/

相关文章:

ios - XCode 工作区完整性错误

python - 在 README.rst 中如何链接到文档文件夹中的图像?

tomcat - 在 DNS 上部署网站后无法访问 Tomcat UI

java - 重新创建没有依赖项的 GitHub 项目 (Java)

GitFlow,压缩和 merge 问题

git - 自动将推送的文件从一个 GitHub 存储库复制到另一个

java - 如何使用 Eclipse 将现有存储库导入到 Java 项目中?

hibernate - java.lang.NoSuchMethodError : javax/persistence/spi/PersistenceUnitInfo. getValidationMode()Ljavax/persistence/ValidationMode

ios - 将 React-Native App 部署到 App Store 的指南

linux - 从 node.js 作为子进程运行 git?