英文:
Detect whether git lfs was installed
问题
我正在使用Ansible在我的服务器上设置Git和Git LFS。
当我运行git lfs install
时,它会显示:
> Git LFS initialized.
当我再次运行它时,它会显示相同的内容并返回状态码0
。这导致Ansible任务不具有幂等性 - 它似乎每次都会安装(而不仅仅是第一次)。
有没有办法检测它是否实际上是通过该命令安装的?或者,如何判断它是否当前已安装?
英文:
I'm using ansible to setup git and git lfs on my server.
When I run git lfs install
it says:
> Git LFS initialized.
When I run it again, it says the same thing and returns status code 0
. That makes ansible tasks not idempotent - it appears as if it is installed every time (rather than just the first time).
Is there some way to detect whether it was actually installed by that command? Alternatively, how can I tell whether it is currently installed?
答案1
得分: 1
Sure, here's the translated content:
当安装了git lfs时,它会添加内容到 ~/.gitconfig
(如果不存在,则会创建)。
它添加了这个:
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
我的ansible任务:
- ansible.builtin.shell: "grep '[filter \"lfs\"]' /home/{{ansible_user}}/.gitconfig 2>/dev/null | wc -l"
register: result
changed_when: false
- ansible.builtin.command: git lfs install
when: result.stdout == '0'
如果文件不存在,或存在但不包含文本 [filter "lfs"]
,则第二个任务将运行 git lfs install
。
英文:
When git lfs is installed, it adds stuff to ~/.gitconfig
(which is created if it does not exist).
It adds this:
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
My ansible tasks:
- ansible.builtin.shell: "grep '[filter \"lfs\"]' /home/{{ansible_user}}/.gitconfig 2>/dev/null | wc -l"
register: result
changed_when: false
- ansible.builtin.command: git lfs install
when: result.stdout == '0'
If the file does not exist, or does exist but does not contain the text [filter "lfs"]
, then the second task will run git lfs install
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论