The best way to apply a git patch via Ansible -
i need deploy bunch of ubuntu servers in same way, thought of using ansible instead of doing manually each time need new one.
one of things need git clone upstream repo, , apply custom patch it. hoping save patch in ansible directory under files/, there doesn't seem "git apply" function in git ansible module. what's best practise of doing this?
some options:
- run own git repo branch including patch. work, have maintain own git repo somewhere , make sure servers have access/permissions it. nice if configurations kept in ansible directory instead of relying on git repo have maintain.
- use shell or command module. easiest working, won't able re-run playbook.
- other suggestions?
write shell script attempts patch git repository local patch.
handle various possibilities :
- being invoked during cookbook re-run.
- the latest upstream source containing identical change local patch.
- the local patch no longer being applicable on latest upstream source.
a sample shell script template above :
# sync local copy latest changes upstream git repository. # todo : check here return code of "git am" failure. # # if <filename.patch> applied, : # - cookbook re-run, # or # - latest upstream source comes patch applied. # display/log info message , skip end of script. # patch latest upstream source local patch echo "attempting apply <filename.patch>..." cd <local-clone-dir> git <filename.patch> # todo : check here return code of "git am" failure. # # in case <filename.patch> no longer applies # latest version of source upstream repo, # display/log error , abort immediately. echo "successfully applied <filename.patch>." # continue rest of tasks.
Comments
Post a Comment