官术网_书友最值得收藏!

Setting node-specific data with Hiera

In our hierarchy defined in hiera.yaml, we created an entry based on the hostname fact; in this section, we'll create yaml files in the hosts subdirectory of Hiera data with information specific to a particular host.

Getting ready

Install and configure Hiera as in the last section and use the hierarchy defined in the previous recipe that includes a hosts/%{hostname} entry.

How to do it...

The following are the steps:

  1. Create a file at /etc/puppet/hieradata/hosts that is the hostname of your test node. For example if your host is named cookbook-test, then the file would be named cookbook-test.yaml.
  2. Insert a specific message in this file:
    message: 'This is the test node for the cookbook'
  3. Run Puppet on two different test nodes to note the difference:
    t@ckbk:~$ sudo puppet agent -t
    Info: Caching catalog for cookbook-test
    Notice: Message is This is the test node for the cookbook
    [root@hiera-test ~]# puppet agent -t
    Info: Caching catalog for hiera-test.example.com
    Notice: Message is Default Message
    

How it works...

Hiera searches the hierarchy for files that match the values returned by facter. In this case, the cookbook-test.yaml file is found by substituting the hostname of the node into the search path /etc/puppet/hieradata/hosts/%{hostname}.yaml.

Using Hiera, it is possible to greatly reduce the complexity of your Puppet code. We will use yaml files for separate values, where previously you had large case statements or nested if statements.

主站蜘蛛池模板: 峨边| 麻城市| 唐海县| 白河县| 栾川县| 新竹县| 临湘市| 温宿县| 汨罗市| 雅江县| 靖远县| 连城县| 九寨沟县| 安远县| 邵东县| 南溪县| 称多县| 鹿泉市| 鄂尔多斯市| 札达县| 兴海县| 德安县| 南丰县| 青阳县| 昆山市| 巴彦县| 辽源市| 高淳县| 盘山县| 隆尧县| 宁都县| 苏州市| 土默特右旗| 宜君县| 青海省| 呼玛县| 江津市| 石泉县| 景谷| 祁东县| 邵武市|