hiera_include相当于资源types

我正在使用yumrepo内置types。 我可以得到一个基本的整合hiera工作

yumrepo { hiera('yumrepo::name') : metadata_expire => hiera('yumrepo::metadata_expire'), descr => hiera('yumrepo::descr'), gpgcheck => hiera('yumrepo::gpgcheck'), http_caching => hiera('yumrepo::http_caching'), baseurl => hiera('yumrepo::baseurl'), enabled => hiera('yumrepo::enabled'), } 

如果我尝试删除该定义,而不是去hiera_include('classes') ,这是我在相应的yaml后端

 classes: - "yumrepo" yumrepo::metadata_expire: 0 yumrepo::descr: "custom repository" yumrepo::gpgcheck: 0 yumrepo::http_caching: none yumrepo::baseurl: "http://myserver/custom-repo/$basearch" yumrepo::enabled: 1 

我在代理上遇到这个错误

SERVER上的错误400:无法find类yumrepo

我想你不能脱离某种最小的节点声明w / hiera和资源types? 也许hiera_hash是要走的路?

我给了这个镜头,但是它产生了一个语法错误

  yumrepo { 'hnav-development': hiera_hash('yumrepo') } 

我已经结束了使用create_resources 。 从本质上讲,它提供了将定义的types映射到具有hiera的节点的function,与hiera_include与hiera_include即用的hiera_include

使用这个设置,我可以在层次结构的任何级别声明任意数量的file资源types,再加上configuration都在hiera数据源中。

/etc/hiera.yaml

 :hierarchy: - defaults - "%{environment}" 

/var/lib/hiera/defaults.yaml

 classes: - hiera_file_wrapper hiera_file: hiera-two: path: /home/quickshiftin/hiera-two ensure: file content: 'Hiera two' 

/var/lib/hiera/production.yaml

 hiera_file: hiera-baby: path: /home/quickshiftin/hiera-baby ensure: file content: 'Hiera baby! 

模块/ hiera_file_wrapper / manifestes / init.pp

 class hiera_file_wrapper() { create_resources(file, hiera_hash('hiera_file')) } 

manifestes / site.pp

 hiera_include('classes') 

由于yumrepo是一种资源types,而不是一个类,这是行不通的。

我会说一个名为yumrepo_myreponame的类,让它声明yumrepo资源。 如果你需要的话,你可以在Hiera中join类参数,然后将这些parameter passing给资源声明。

例如,我有一个用于打开EPEL的模块,用于服务器,可以放在Hiera classes数组中以启用它。 其全部内容是:

 class epel_yumrepo { yumrepo { "epel": descr => 'Extra Packages for Enterprise Linux 6 - $basearch', enabled => 1, gpgcheck => 1, gpgkey => 'http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6', mirrorlist => 'https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch', failovermethod => "priority", } } 

假设您有一个名为hnav的yum存储库,并且您需要根据您使用的操作系统版本5或6来使用不同的URL。

你在/etc/puppet/hiera.yaml中configuration了你的层次结构

 :hierarchy: - "%{::operatingsystemmajrelease}" - common 

因此,hiera将首先查找以OS版本5.yaml6.yaml命名的yaml文件。 如果它没有在那里find一个值,它将看起来common.yaml

你写了一个参数化的类,以便hiera可以自动提供URL。

模块/ hnav / manifests.init.pp

 class hnav ( $url ) { yumrepo { 'hnav': enabled => true, baseurl => $url } } 

如果由于某种原因你不喜欢参数化的类,那么你可以把上面的语句写成

 class hnav { yumrepo { 'hnav': enabled => true, baseurl => hiera('hnav::url') } } 

然后,您将所需的类configuration到所有节点上

common.yaml

 classes: - hnav 

并设置url的值

5.yaml

 hnav::url: http://example.com.yum/5/ 

6.yaml

 hnav::url: http://example.com.yum/6/ 

这是一个非常人造的例子,但也许它会帮助你了解hiera的用途。

我在我的工作中构build了hiera_manifestfunction。 本质上它允许你通过hiera yaml调用模块,类和参数以及定义的types。

我只是把它放在Github上分享: https : //github.com/mlbam/hiera_manifest

这有一个小的优点,因为在调用模块,类或types的时候,这些参数也被使用了。

需要注意的一点是,在使用元参数时,资源定义的一些语法有所不同。 此外,在进行故障排除时,错误有时会粘在清单上,而您没有得到引发错误的模块的正确错误消息。