Hi
Just wondering if anyone else is doing git sparse-checkouts in ansible playbooks ?
Maybe they have a better idea than me..
The way to do it is this:
mkdir <repo> && cd <repo>
git init
git remote add –f <name> <url>
Enable sparse-checkout in the repo:
git config core.sparsecheckout true
Configure sparse-checkout by listing your desired sub-trees in .git/info/sparse-checkout:
echo some/dir/ >> .git/info/sparse-checkout
echo another/sub/tree >> .git/info/sparse-checkout
Checkout from the remote:
git pull <remote> <branch>
If repo was already checked out before sparse checkout was done, do:
git read-tree -mu HEAD
The way I'm writing my playbook is this:
tasks:
- name: getting my git repo
git: repo=gito...@my.git dest=/bla remote=origin version=production
- name: enable sparse-checkout
shell: git config core.sparsecheckout true chdir=/bla creates=/bla/.git/info/sparse-checkout
notify: sparse-checkout
- name: reset folder to only contain sparse structure if it was previously created
shell: git read-tree -mu HEAD chdir=/bla
handlers:
- name: sparse-checkout
copy: files/sparse-checkout dest=/bla/.git/info/sparse-checkout
The thing I don't like about this, is I have to checkout my git repo before hand if I want to use the Ansible module, otherwise I need to do custom commands to init the repo myself, or am I missing something?
If anyone else are doing this please show me if it can be done better.