1. 环境准备

   OS:CentOS 6.4

   关闭selinux和iptables

   部署Puppet: 

   安装Puppet源:http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm 

   完成PuppetMaster/Agent的部署,证书签署...

   Hiera是一个key/value配置数据的查找工具,可以用来方便的配置特殊节点配置数据.

2. 使用Hiera

  a) 安装hiera

    如果安装的是Puppet 3.7不需要再安装Hiera了..

    如果安装的是2.7版本,需要执行下面的命令.

yum install hiera hiera-puppet -y

   b)配置hiera.yaml

    查看配置文件的路径

puppet master --configprint hiera_config    #默认在/etc/puppet/hiera.yaml

    hiera的配置文件必须是YAML hash格式.

#一个参考的配置..,注意每个最顶层的配置,前面必须要有一个 : ---:backends:  - yaml  - json:yaml:  :datadir: /etc/puppet/hieradata:json:  :datadir: /etc/puppet/hieradata:hierarchy:  - "%{::clientcert}"  - "%{::custom_location}"  - common#如果hiera.yaml存在,但是里面是空的..,那么它的默认配置如下..---:backends: yaml:yaml:  :datadir: /var/lib/hiera:hierarchy: common:logger: console

    c) 配置参数

#顶层配置:hierarchy  #必须是一个字符串或数组,每一个名字都代表一个静态或动态数据源  #动态数据是一个简单的 %{variable} 内插变量  #在层次结构中,按顺序检查,自上而下.  #默认值是common:backend  #必须是一个字符串或数组,每一个名字都代表一个可用的Hiera的backend  #内置的backend是yaml和json,可以添加额外的backend作为附加的  #默认值是yaml#backend设置:yaml and :json:datadir     #可以在目录中找到数据源的文件,必须是一个字符串  #可以在路径中使用变量内插/etc/puppet/hieradata/%{::environment}  #默认值 /var/lib/hiera#配置hiera.yamlmkdir /etc/puppet/hieradata/cat > /etc/puppet/hiera.yaml <
 /etc/puppet/hieradata/common.yaml <
 /etc/puppet/hieradata/RedHat.yaml <
 /etc/puppet/hieradata/CentOS6.yaml <
 /etc/puppet/manifests/site.pp <
 /etc/puppet/modules/base/manifests/init.pp <

3. 执行Puppet Agent

[root@agent1 ~]# puppet agent --verbose --no-daemonizeNotice: Starting Puppet client version 3.7.3Info: Retrieving pluginfactsInfo: Retrieving pluginInfo: Caching catalog for agent1.dbsa.cnInfo: Applying configuration version '1417636182'Notice: OS1: CentOSNotice: /Stage[main]/Base/Notify[OS1: CentOS]/message: defined 'message' as 'OS1: CentOS'Notice: OS2: CentOSredhatdefaultNotice: /Stage[main]/Base/Notify[OS2: CentOSredhatdefault]/message: defined 'message' as 'OS2: CentOSredhatdefault'Notice: Finished catalog run in 0.03 seconds^CNotice: Caught INT; calling stop[root@agent1 ~]# facter operatingsystemCentOS[root@agent1 ~]# facter operatingsystemmajrelease6