基于模式的Hiera查找

我想包围我的头如何我可以从我在我的大site.pp文件中进行过渡到我可以在hiera中使用的结构。 从阅读傀儡文档来看,我不清楚这些文档究竟是如何评估以及何时适合这些图片的。 我最近从puppet 2.7.x升级到3.3.x. 这包括hiera作为标准包的一部分,所以我想最后看看使用这个,因为它应该使我的设置更容易阅读/理解。

我正在使用支持系统几个外部组织。 这包括configuration每个组织独有的系统。 在我的网站顶部,我有一个像下面的结构。 我使用哪个设置事实为每个组织基于一个正则expression式匹配的clientcert事实configuration和发布的方式,他们将可靠地识别每个组织。

# match organization case $::clientcert { /.*example1.org/ : { $snmp_ro_community='...' $snmp_location='Example Org 1' ... } /.*example2.org/ : { $snmp_ro_community='...' $snmp_location='Example Org 2' ... } /.*example3.org/ : { $snmp_ro_community='...' $snmp_location='Example Org 3' ... } /.*example4.org/ : { $snmp_ro_community='...' $snmp_location='Example Org 4' ... } } 

我浏览示例我没有看到任何方式在我的hiera.yaml文件中做任何forms的匹配。 我怀疑我一定是错过了一些明显的东西。

我不想依赖于这个自定义的事实。 我更愿意坚持客户端证书,因为我确信这将正确识别组织和系统,并且已经使用强大的密码学得到证实。 我不想把这个组织的价值赋予另一个组织。

您可以设置YAML文件的层次结构。 让我们从hiera.yaml开始:

 --- :hierarchy: - "host/%{fqdn}" - "domain/%{domain}" - "env/%{::environment}" - "ops/%{operatingsystem}" - "os/%{osfamily}" - common :backends: - yaml :yaml: :datadir: /etc/puppet/data 

对于文件夹结构,您可以使用任何可以在facter -y输出中看到的事实。 例如,您可以为每个CPU架构configurationhieraconfiguration文件。 然后你会添加行

 - "arch/%{::architecture}" 

和hiera会看起来让我们说到arch/amd64.yaml

要debugginghiera,你可以转储你当前的事实:

  $ facter -y > myhost.yaml 

并寻找一些variables:

  $ hiera -y myhost.yml snmp_location --debug 

Hiera将通过所有规则并尝试查找variables:

 DEBUG: Mon Nov 11 11:00:23 +0100 2013: Hiera YAML backend starting DEBUG: Mon Nov 11 11:00:23 +0100 2013: Looking up snmp_location in YAML backend DEBUG: Mon Nov 11 11:00:23 +0100 2013: Looking for data source host/myhost.example.com ... DEBUG: Mon Nov 11 11:00:23 +0100 2013: Looking for data source ops/Ubuntu DEBUG: Mon Nov 11 11:00:23 +0100 2013: Cannot find datafile /etc/puppet/data/ops/Ubuntu.yaml, skipping 

为了匹配$::clientcert ,将顶层域提取为一个单独的事实可能是个好主意,然后只需要包含cert/example1.org.yaml yaml文件就可以了,如下所示:

 --- snmp_location: 'Example Org 1' 

很高兴知道,即使您的模块不包含任何hiera函数调用,您也可以轻松设置参数值:

 class snmp ( $location = 'foo', ) { # ... } 

一些hieraconfiguration:

 --- snmp::location: 'Example Org 1' 

我也因为类似的原因寻找同样的东西。 并发现hiera在github中有帮助jjulien / hiera-regex 。 作为项目本身自述文件的一个例子:你必须configuration一个新的后端来处理分组,如下所示:

/etc/puppet/hiera.yaml:

 :backends: - regex - yaml :yaml: :datadir: /var/lib/hiera :regex: :datadir: /var/lib/hiera :hierarchy: - "fqdn/%{::fqdn}" - common 

/var/lib/hiera/fqdn/fqdn.regex:

 --- - '^mailin-trusted.example.org$': postfix::smtp_relay: 'mailout-dmz.example.org' - '^mailout.*': postfix::smtp_relay: 'smtp.mailgun.org' - '^mailin.*': postfix::smtp_relay: 'localhost' 

然而,我看到几个木偶用户的post和puppetlabsvideo警告反对使用hiera进行分类,尤其是现在随着节点pipe理器发布的PE 3.7。