我正在尝试使用Puppet facter获取根分区(mountpoint => "/")
名称。当我运行"facter mountpoints"
时,它会显示多个分区。我想从结果中获取变量"/dev/md3"
。
{
/ => {
available => "893.71 GiB",
available_bytes => 959608590336,
capacity => "1.86%",
device => "/dev/md3",
filesystem => "ext4",
options => [
"rw",
"errors=remount-ro"
],
size => "910.69 GiB",
size_bytes => 977843884032,
used => "16.98 GiB",
used_bytes => 18235293696
},
/run => {
available => "794.91 MiB",
available_bytes => 833527808,
capacity => "0.07%",
device => "tmpfs",
filesystem => "tmpfs",
options => [
"rw",
"noexec",
"nosuid",
"size=10%",
"mode=0755"
],
size => "795.48 MiB",
size_bytes => 834125824,
used => "584.00 KiB",
used_bytes => 598016
},
/tmp => {
available => "1.78 GiB",
available_bytes => 1909157888,
capacity => "1.21%",
device => "/dev/md1",
filesystem => "ext4",
options => [
"rw"
],
size => "1.80 GiB",
size_bytes => 1932533760,
used => "22.29 MiB",
used_bytes => 23375872
}
}
我尝试使用过滤器,但我无法过滤"/"
设备。
$root_mount = $facts['mountpoints'].filter |$mountpoint| { $mountpoint == '/' }
你们有什么想法吗?
答案 0 :(得分:2)
您可以通过哈希表示法直接访问此事实。由于你的问题很大程度上暗示你正在使用Facter 3 / Puppet 4,我将使用这种语法。
您只需直接遍历Facter哈希中的键即可获得/dev/md3
值。如果我们将哈希值从facter mountpoints
最小化到相关部分:
{
/ => {
device => "/dev/md3"
}
}
然后我们看到密钥是mountpoints
(您在CLI中facter mountpoints
时直接访问了该密钥),/
和device
。因此,在Puppet中使用带有$facts
哈希的标准哈希表示法,我们可以使用以下命令访问该值:
$facts['mountpoints']['/']['device'] # /dev/md3
点击此处了解详情:https://docs.puppet.com/puppet/4.9/lang_facts_and_builtin_vars.html#the-factsfactname-hash