从特定variables/ fact / hiera-value加载hiera文件

我正在试图根据一个特定的标志加载一个hiera文件。

Hiera hierarachyconfiguration是

:hierarchy: - "%{environment}/%{::fqdn}" - "%{environment}/%{nodetype}" - "%{environment}/%{calling_module}" - "%{environment}" - "common/%{calling_module}" - "common" 

事实上,想要在“节点types”级别上分解一些configuration。 目标是避免在文件中放置相同的hiera“块”:

  • 环境/testing/ myhost1.example.com.yaml
  • 环境/testing/ myhost2.example.com.yaml
  • 环境/testing/ myhost3.example.com.yaml

但相反,但共同的部分在:

  • environment / test / nfs-server.yaml为所有与nfs服务器相关的常用configuration
  • 环境/testing/后端服务器.yaml所有后端服务器相关的共同点

之后,所有的服务器都会通过fqdn yaml文件获得自己的特定值。 (这部分是确定的)

目前,我不知道如何将“nodetype”数据提供给hiera上下文。

我试图把它放在主要的清单文件中(是​​的,我读了文档,我知道这是一个坏主意,但即使绝望的尝试,它不工作)

 node 'nfs1.example.com', 'nfs2.example.com' { $nodetype= 'nfs-server' 

但文件environment / test / nfs-server.yaml不是由hiera加载的。

我也尝试使用自定义事实,但使用自定义的事实

 modules/hosts/facts.d/host-fact-test.txt 

文件发送到代理的主机,但在这里,hiera不使用专用文件。

 Notice: /File[/var/lib/puppet/facts.d/host-fact-test.txt]/ensure: defined content as '{md5}d7492faae1bfe55f65f9958a7a5f6df9' 

如果我使用通知 puppet命令,则值为ok

 if $nodetype== 'nfs-server' { notify {"Running with \$nodetype ${nodetype} ID defined": withpath => true, } } 

结果:

 Notice: /Stage[main]/attemps/Notify[Running with $nodetype nfs-server ID defined]/message: Running with $nodetype nfs-server ID defined 

Stack是Ubuntu 14上的Puppet开源,所以版本是:

  • 木偶3.8.4
  • hiera 1.3.4
  • 因素2.4.4

任何想法或build议,使其工作(或实现类似的行为)?

Puppet主进程通常不使用/etc/hiera.yaml的configuration,这可能会造成混淆。 使用Puppet 3.x ,通常是/etc/puppet/hiera.yaml

你可以确保使用(以root身份)

 puppet master --configprint hiera_config 

在主机上。