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