我需要以相同的方式部署一堆Ubuntu服务器,所以我想使用ansible而不是每次需要新的时都手动执行它。
我需要做的一件事就是git克隆一个上游repo,并为它应用一个自定义补丁。我希望将补丁保存在我的ansible目录下的files /下,但是在git ansible模块中似乎没有“git apply”函数。做这样的事情的最佳做法是什么?
一些选项:
答案 0 :(得分:2)
编写一个shell脚本,尝试使用本地补丁修补git存储库。
处理各种可能性,例如:
- 在食谱重播期间被调用。
- 最新的上游源已经包含与本地补丁相同的更改。
- 本地补丁不再适用于最新的上游源。
# sync the local copy with latest changes from the upstream git repository.
# TODO : Check here for return code of "git am" for failure.
#
# If <filename.patch> already applied, then :
# - This is probably a cookbook re-run,
# or
# - The latest upstream source now comes with the patch applied.
# Display/Log an info message about this and skip to the end of the script.
# Patch latest upstream source with a local patch
echo "Attempting to apply <filename.patch>..."
cd <local-clone-dir>
git am <filename.patch>
# TODO : Check here for return code of "git am" for failure.
#
# In case <filename.patch> no longer applies
# to the latest version of the source from upstream repo,
# display/log the error and abort immediately.
echo "Successfully applied <filename.patch>."
# Continue with rest of the tasks.