4

I'm trying to use a node scope variable in my hiera.yaml config, which apparently should be relatively simple, but it's just not working for me Lol

With the hiera.yaml like this:

---
:backends:
    - yaml
:yaml:
    :datadir: /etc/puppet/hieradata
:hierarchy:
    - nodes/%{::hostname}
    - builds/%{build}
    - common

And my site.pp like so:

hiera_include('classes')
node 'mynode' {
    $build = special
}

And the other yaml files,

common.yaml:

---
classes:
    - first_class
    - second_class

builds/special.yaml:

---
classes:
    - third_class

I would expect 'mynode' to get the 'third_class' when the puppet agent is refreshed, but it doesn't, and gives no error.

Running the hiera command gives me the correct (I think) output:

$ hiera classes
["first_class","second_class"]
$ hiera classes build=special
["third_class"]

Is there something glaringly obvious that I've done wrong here?

The %{::hostname} works. If I add nodes/mynode.yaml, that config is picked up.

4

1 回答 1

1

经过几个小时的挠头,在 puppetlabs 上报告了一个文档错误(我现在已经关闭了,哈哈),几乎完全放弃了这个想法,只是创建了一个自定义事实,我发现这是一个非常简单的修复......而且它是有道理的。 ..

基本上我需要做的就是改变我的site.pp:

hiera_include('classes')
node 'mynode' {
    $build = special
}

至:

node 'mynode' {
    $build = special
    hiera_include('classes')
}

现在很有意义,因为如您所见,我需要hiera_include在设置节点范围变量后调用。

不过需要注意的是(正如我刚刚发现的那样),如果您hiera_include('classes')在顶层有 并且您在多个 yaml 文件中设置类参数,它将仅使用 common.yaml 中设置的参数。

可能最烦人的事情是,通过我所有的试验和错误,我在某个时候做hiera_include了节点声明,我只是没有把它放在变量 Lol 之后

于 2015-11-13T19:43:52.283 回答