从 Puppetfile 中找到 Git 参考
Find Git reference from Puppetfile
在我们复杂的 Puppet 环境中,我们使用一个大的 Puppetfile,它总是为每个模块列出其 Git URL (:git
) 和引用 (:ref
):
(...)
mod 'foobar',
:git => 'ssh://git@bitbucket.example.com:7777/pup/puppet-foobar.git',
:ref => 'puppet-foobar-3.14'
(...)
模块版本一直在更新,所以:ref
的值经常变化。
当我们通过命令行 运行 Puppet 代理时,有没有办法知道哪个 :ref
应用于特定的 运行?
Puppet master 在生成的每个目录中都包含一个版本号,您可以通过 config_version
环境设置对其进行自定义。
代理运行并应用目录时会记录和显示:
Info: Applying configuration version '1488468780'
(显示默认,编译的Unix/epoch时间戳)
这可以是任何数据,包括时间戳、SCM 修订号(例如 git SHA)或更易于阅读的内容。
如果您有很多模块,最好使用 Puppetfile 本身的修订版,假设它在源代码管理中被跟踪。如果使用 git,您可能会使用 git rev-parse HEAD
来获取当前版本。
配置 environment.conf 中的 config_version
参数(docs,例如 /etc/puppetlabs/code/environments/production/environment.conf
)以指向脚本:
config_version = '/usr/bin/git --git-dir $confdir/environments/$environment/.git rev-parse HEAD'
(来自 R10k + Directory Environments - Gary Larizza)
R10k 也有一个很好的基于 git 的脚本,您可能会发现它很有用:config_version.sh,其中包括最新的提交消息和 SHA。
在我们复杂的 Puppet 环境中,我们使用一个大的 Puppetfile,它总是为每个模块列出其 Git URL (:git
) 和引用 (:ref
):
(...)
mod 'foobar',
:git => 'ssh://git@bitbucket.example.com:7777/pup/puppet-foobar.git',
:ref => 'puppet-foobar-3.14'
(...)
模块版本一直在更新,所以:ref
的值经常变化。
当我们通过命令行 运行 Puppet 代理时,有没有办法知道哪个 :ref
应用于特定的 运行?
Puppet master 在生成的每个目录中都包含一个版本号,您可以通过 config_version
环境设置对其进行自定义。
代理运行并应用目录时会记录和显示:
Info: Applying configuration version '1488468780'
(显示默认,编译的Unix/epoch时间戳)
这可以是任何数据,包括时间戳、SCM 修订号(例如 git SHA)或更易于阅读的内容。
如果您有很多模块,最好使用 Puppetfile 本身的修订版,假设它在源代码管理中被跟踪。如果使用 git,您可能会使用 git rev-parse HEAD
来获取当前版本。
配置 environment.conf 中的 config_version
参数(docs,例如 /etc/puppetlabs/code/environments/production/environment.conf
)以指向脚本:
config_version = '/usr/bin/git --git-dir $confdir/environments/$environment/.git rev-parse HEAD'
(来自 R10k + Directory Environments - Gary Larizza)
R10k 也有一个很好的基于 git 的脚本,您可能会发现它很有用:config_version.sh,其中包括最新的提交消息和 SHA。