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

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.

主站蜘蛛池模板: 定襄县| 陈巴尔虎旗| 那坡县| 英超| 博乐市| 长沙市| 阿拉善左旗| 深水埗区| 漳平市| 山阳县| 上饶县| 中卫市| 丹阳市| 东兴市| 安阳市| 军事| 罗山县| 揭阳市| 佛教| 盐城市| 龙里县| 都兰县| 板桥市| 房产| 闸北区| 宜宾县| 巩留县| 鄂托克前旗| 长垣县| 会昌县| 长乐市| 壤塘县| 宜宾市| 石城县| 阿巴嘎旗| 开鲁县| 江川县| 德州市| 海门市| 离岛区| 揭阳市|