如何使用源存储库中的 Hiera 数据?

如何使用源存储库中的 Hiera 数据?

我有一个无主控的 Puppet 设置,我想简单地添加一些信息,例如基于$::osfamily可移植性的包名称。Hiera 似乎就是为这类事情而设计的,但我不知道如何真正做到这一点在同一源存储库内的 Puppet 清单中使用源存储库内的 Hiera 数据不修改任何事物/etc。基本上,每一份文档似乎都假设每当我使用不同的存储库时我都想要修改/etc/puppetlabs/code/hiera.yaml/etc/puppetlabs/puppet/puppet.conf手动修改。或者我完全误解了希拉?

如果有必要,我可以将 puppet.conf 添加到存储库并在每次运行时引用它puppet apply,但是我将如何引用当前目录作为根hiera_config

答案1

是的,您可以通过无主设置使用 hiera 数据。只需在 hiera 配置中指定 --hiera_config 即可指定在何处查找 hiera 数据。

例子:

nkts@trololo:/tmp/puppet$ puppet apply -t --modulepath=./modules/ --hiera_config=./hiera.conf manifests/a.pp
Notice: Compiled catalog for trololo.lan in environment production in 0.31 seconds
Info: Applying configuration version '1449108414'
Notice: test: bar
Notice: /Stage[main]/A/Notify[test: bar]/message: defined 'message' as 'test: bar'
Notice: Applied catalog in 0.02 seconds
nkts@trololo:/tmp/puppet$ cat hiera.conf
---
:backends: yaml
:yaml:
  :datadir: /tmp/puppet/data
:hierarchy: common
:logger: console
nkts@trololo:/tmp/puppet$ cat data/common.yaml
a::foo: bar
nkts@trololo:/tmp/puppet$ cat manifests/a.pp
class { "a":
}
nkts@trololo:/tmp/puppet$ cat modules/a/manifests/init.pp
class a (
  $foo = "default msg"
){
  notify { "test: $foo":
  }
}
nkts@trololo:/tmp/puppet$ rm data/common.yaml
nkts@trololo:/tmp/puppet$ puppet apply -t --modulepath=./modules/ --hiera_config=./hiera.conf manifests/a.pp
Notice: Compiled catalog for trololo.lan in environment production in 0.32 seconds
Info: Applying configuration version '1449108454'
Notice: test: default msg
Notice: /Stage[main]/A/Notify[test: default msg]/message: defined 'message' as 'test: default msg'
Notice: Applied catalog in 0.02 seconds
nkts@trololo:/tmp/puppet$

相关内容