深入探究 Hiera 与 PuppetDB:管理 Puppet 数据与资源的利器
1. Puppet 代码中处理哈希
在 Puppet 代码里,哈希可用于表达复杂且结构化的数据。Hiera 始终返回首个定义层级键的值。例如,以下是一个嵌套哈希的示例:
network::interfaces_hash:
eth0:
ipaddress: 10.0.0.193
netmask: 255.255.255.0
network: 10.0.0.0
broadcast: 10.0.0.255
gateway: 10.0.0.1
post_up:
- '/sbin/ifconfig eth3 up'
- '/sbin/ifconfig eth4 up'
eth2:
enable_dhcp: true
eth3:
auto: false
method: manual
eth4:
auto: false
method: manual
在 Puppet 代码中,可按如下方式创建变量来加载该哈希:
$int_hash=hiera('network::interfaces_hash')
要引用其数据结构中的单个值,可使用以下代码:
$ip_eth0=$int_hash['eth0']['ipaddress
超级会员免费看
订阅专栏 解锁全文
8

被折叠的 条评论
为什么被折叠?



