我试图弄清楚如何使用 hiera 来设置类参数的值。我正在用两个简单的类进行测试:testhiera 和 testhiera2
以下是这些课程:
[root@puppet-el7-001 modules]# cat testhiera/manifests/init.pp
class testhiera (
$haproxy_cert_content = 'unknown' ,
) {
notify {"cert is $haproxy_cert_content":}
}
[root@-puppet-el7-001 modules]# cat testhiera2/manifests/init.pp
class testhiera2 (
$haproxy_cert_content = 'unknown' ,
) {
notify {"number two cert is $haproxy_cert_content":}
}
这是我的 /etc/puppletlabs/puppet/hiera.yaml 文件
---
:backends:
- yaml
:hierarchy:
- defaults
- "%{clientcert}"
- "%{environment}"
- global
:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /var/lib/hiera on *nix
# - %CommonAppData%\PuppetLabs\hiera\var on Windows
# When specifying a datadir, make sure the directory exists.
:datadir: /root/puppetmaster/hiera/ost-el7
我有这个文件 /root/puppetmaster/hiera/ost-el7/defaults.yaml
一个附带问题:我必须将文件命名为“defaults.yaml”吗?我怎么能使用另一个文件名?
---
testhiera::haproxy_cert_content: "\n
-----BEGIN CERTIFICATE-----\n
blah blah blha\n
-----END RSA PRIVATE KEY-----\n
blah blah blha\n
-----BEGIN CERTIFICATE-----\n
blah blah blha\n
-----END CERTIFICATE-----\n
"
当我像这样执行我的木偶类时......
# puppet apply -e 'include testhiera'
...我得到了预期的输出:
Notice: Compiled catalog for puppet-el7-001.cisco.com in environment production in 0.08 seconds
Notice: cert is
-----BEGIN CERTIFICATE-----
blah blah blha
-----END RSA PRIVATE KEY-----
blah blah blha
-----BEGIN CERTIFICATE-----
blah blah blha
-----END CERTIFICATE-----
Notice: /Stage[main]/Testhiera/Notify[cert is
-----BEGIN CERTIFICATE-----
blah blah blha
-----END RSA PRIVATE KEY-----
blah blah blha
-----BEGIN CERTIFICATE-----
blah blah blha
-----END CERTIFICATE-----
]/message: defined 'message' as 'cert is
-----BEGIN CERTIFICATE-----
blah blah blha
-----END RSA PRIVATE KEY-----
blah blah blha
-----BEGIN CERTIFICATE-----
blah blah blha
-----END CERTIFICATE-----
'
Notice: Finished catalog run in 0.17 seconds
我的问题是将 haproxy_cert_content 数据获取到 testhiera2 类的最佳方法是什么?我是否必须将我的 defaults.yaml 文件更改为如下所示...
---
testhiera::haproxy_cert_content: "\n
-----BEGIN CERTIFICATE-----\n
blah blah blha\n
-----END RSA PRIVATE KEY-----\n
blah blah blha\n
-----BEGIN CERTIFICATE-----\n
blah blah blha\n
-----END CERTIFICATE-----\n
"
testhiera2::haproxy_cert_content: "\n
-----BEGIN CERTIFICATE-----\n
blah blah blha\n
-----END RSA PRIVATE KEY-----\n
blah blah blha\n
-----BEGIN CERTIFICATE-----\n
blah blah blha\n
-----END CERTIFICATE-----\n
"
...基本上只是剪切-n-粘贴行并将testhiera更改为testhiera2?
我希望有人能告诉我一个更好的方法来做到这一点。
谢谢