我目前在无主模式下运行Puppet。 我正在使用r10k进行模块和环境部署。
简化版本:r10k控制库有两个分支: testing和生产 。 生产中的变化将被自动分配到生产服务器。 对某些分段服务器的testing更改。
现在,如果我在testing中改变事情,我有时也必须更改r10k控制库。 一个常见的例子是Puppetfile ,目前在生产中看起来像这样:
forge 'forge.puppetlabs.com' # Forge modules mod 'puppetlabs/stdlib' mod 'puppetlabs/concat' mod 'saz/ssh' # Custom modules mod 'ownmodule1', :git => 'https://git.example.org/configuration/ownmodule1.git', :ref => 'production' mod 'ownmodule2', :git => 'https://git.example.org/configuration/ownmodule2.git', :ref => 'production'
自定义模块的configuration在testing分支上可能如下所示:
mod 'ownmodule1', :git => 'https://git.example.org/configuration/ownmodule1.git', :ref => 'testing' mod 'ownmodule2', :git => 'https://git.example.org/configuration/ownmodule2.git', :ref => 'testing'
现在, testing提交可能看起来像这样:
+mod 'ownmodule3, + :git => 'https://git.example.org/configuration/ownmodule3.git', + :ref => 'testing'
如果我将它合并到生产中 ,并且不小心, 那么ownmodule3将会与testing分支一起被添加到生产中 ,这可能是致命的。 当所有testing成功时,这也防止自动合并。
如何修改我的存储库或工作stream以防止意外合并分支机构特定更改?
replace用当前环境名称replacevariables的Puppetfile用作ref的硬编码环境名称将有助于使您的Puppetfile在分支之间合并。
伪代码:
mod 'ownmodule1', :git => 'https://git.example.org/configuration/ownmodule1.git', :ref => ${environment}
对于实际的代码看到这个答案 ,但我不能保证它会在你的设置工作,这有点hacky。
但是,当然,为了让你的环境在这个改变之后能够正确的部署,你必须在你的模块中创buildproduction分支并进行testing并且使用一些最小的无操作但是为新模块编译代码来初始化它们。
PS如果这个答案是有用的,你决定放弃它,那么请upvote链接的答案了。
由于r10k 2.4.0 ,傀儡模块可以与控制库中的分支相匹配。 在分支testing ,我的问题中的Puppetfile可能如下所示:
mod 'ownmodule1', :git => 'https://git.example.org/configuration/ownmodule1.git', :ref => :control_branch
这将导致在r10k部署中使用模块ownmodule的分支testing 。 这是相当可靠的。 用:default_branch你可以指定一个后备分支。