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?
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
.