我正在使用Ansible(Trellis)来部署我的项目。
我在Github上有一个仓库。
我的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
这是我有时候
,因为没有明显原因出现此错误
失败! => {“更改”:false,“ cmd”:“/usr/bin/git ls -remote rient -h refs/head/master”,“ msg”:“ fatal:'Origin'似乎不是Git存储库\ nfatal:无法从远程存储库中读取。\ n \ nplease确保您拥有正确的访问权限\ n和存储库存在。 git存储库\ nfatal:无法从远程存储库中读取。\ n \ nplease请确保您拥有正确的访问权限\ nand。成为一个git存储库“,“致命:无法从远程存储库中读取。”,“”,“请确保您拥有正确的访问权限”,并且存储库存在。”],“ stdout”:“”:“”,“” stdout_lines”:[]}
我尝试了几种解决方案,甚至删除了 forwardagent
,并将 key_file
直接强制到GIT调用中。它仍然返回错误。
但是,如果我通过SSH连接到目标机器,并尝试执行 git克隆....
一切都起作用。
我不明白问题是什么。
I'm using ansible (Trellis) to deploy my projects.
I have a repo on github.
This is my ansible code
- 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
For some days this error has appeared for no apparent reason, nothing has changed
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": []}
I've tried several solutions, even removing the forwardAgent
and forcing the key_file
directly into the git call. It still returns an error.
But if I connect via ssh to the target machine and try to do a git clone ....
everything works.
I don't understand what the problem could be.
发布评论
评论(3)
总结
几个月前,我也遇到了这一点:
根本原因似乎是Ansible正在运行git作为root (或
susty_user
),而磁盘上的git克隆(故意)由其他人拥有。另外,消息“'Origin'似乎不是Git中的git存储库” 是误导性的。
调试
我必须采取绝望的措施来揭示这一点,即用:查看
/usr/bin/git
使用:查看
/tmp/git-db/git。*。 /code> files(和
ps
启用睡眠)表明Ansible正在运行/usr/bin/git作为root。测试git作为词根,给出了已经发布的解决方法的线索:重现Ansible实际上会在产生的相同的错误消息上cho的GIT调用:
如
已经提到的OP,将目标计算机的目录在目标计算机的GIT中列出了。配置围绕该问题工作:(
编辑:用idempotent语法替换为“ - add”,lust-add将冗余行附加到您的/root/.gitconfig上每个执行(请参阅
git> git-config(1)
)
> 调用没有效果
。和6.2.0(使用PIP安装)。
Summary
I also ran into this a few months ago:
The root cause seems to be that Ansible is running git as root (or
become_user
), while the git clone on disk is (on purpose) owned by someone else.Also, the message "'origin' does not appear to be a git repository" from git is misleading.
Debugging
I had to resort to desperate measures to uncover this, though, namely replacing
/usr/bin/git
with:Looking at the
/tmp/git-db/git.*.id
files (andps
with the sleep enabled) showed that ansible was running /usr/bin/git as root. Testing git as root on the gave a clue to the workaround OP already posted:Reproducing the git invocation that Ansible actually chokes on produced the same broken error message we've seen:
Workaround
As OP already mentioned, whitelisting the directory in the target machine's git configuration works around the issue:
(EDIT: replaced "--add" with idempotent syntax. Using --add appends redundant lines to your /root/.gitconfig on every execution (see
git-config(1)
).What should work, but doesn't
A more appropriate fix would be to execute git as the user that owns the git clone directory. This should be possible with
become_user
, but adding the incantations to the invocation has no effect. With ...... ansible is still executing
/usr/bin/git
as root, evidenced by the wrapper above. This happens on ansible 2.9 and 6.2.0 (installed using pip).添加
和编辑
我解决了问题;)
Adding
and editing
I solve the problem ;)
请注意,
git
Ansible模块的属性应该引用一个私钥,而不是公共密钥。但是首先检查
{{project.git.ssh}}}
的值,以确保它是有效的github ssh url,例如[email  procearted] :me/myrepo
。如果没有,或者是空的,那将解释致命:'Origin'似乎不是Git存储库
错误消息。Note, the
key_file
attribute of thegit
Ansible module is supposed to reference a private key, not the public one.But check first the value of
{{ project.git.ssh }}
, to make sure it is a valid GitHub SSH URL like[email protected]:me/myRepo
. If not, or if empty, that would explain thefatal: 'origin' does not appear to be a git repository
error message.