在事实 2 中,您现在可以将数组/哈希作为事实。
例如:
os => {
"name"=>"CentOS",
"family"=>"RedHat",
"release"=>{
"major"=>"7",
"minor"=>"0",
"full"=>"7.0.1406"
}
}
os=>release=>major
从清单访问的格式是什么?
答案1
例如这样:
notify { $::os[release][major] : }
请注意,您需要设置选项stringify_facts设置为 false 才能使其工作(使用 Puppet 3.7.1 编写时的默认值为 true)。
答案2
您可以使用哈希值从清单中访问事实,如下所示:
notify { $::os['release']['major']: }
例子:
# puppet apply -e 'notify { $::os['release']['major']: }'
Notice: Compiled catalog for mon.adriatic.local in environment production in 0.04 seconds
Notice: 6
Notice: /Stage[main]/Main/Notify[6]/message: defined 'message' as '6'
Notice: Applied catalog in 0.28 seconds
答案3
应该可以像往常一样访问哈希数据类型。
例子:
$myhash = {os => {
"name"=>"CentOS",
"family"=>"RedHat",
"release"=>{
"major"=>"7",
"minor"=>"0",
"full"=>"7.0.1406"
}
}
}
notice( $myhash[os][release][major] )