Puppet 使用 facter 获取根分区名称
Puppet get root partition name using facter
我正在尝试使用 Puppet facter 获取根分区 (mount => "/")
名称。
当我运行“facter partitions
”时,它显示三个分区。
我想从结果中获取变量 "sda3"。
{
/dev/sda1 => {
size => "1.00 MiB",
size_bytes => 1048576
},
/dev/sda2 => {
filesystem => "ext2",
mount => "/boot",
size => "477.00 MiB",
size_bytes => 500170752,
uuid => "8345d60e-e09a-4723-b5a6-149f4002706d"
},
/dev/sda3 => {
filesystem => "ext4",
mount => "/",
size => "49.71 GiB",
size_bytes => 53376712704,
uuid => "a1330fb2-7f13-417e-8908-813b1fdae911"
},
我尝试了 $hddname = $facts['partitions']['mount'] == "/"
,但出现错误。
你们有什么想法吗?
在处理散列和数组时,您可能需要 Puppet Iteration and loops 功能。该页面链接到一些有用的功能,将帮助您找到所需的功能。
首先你需要过滤输入:
$root_partition = $facts['partitions'].filter |$device, $partition| { $partition['mount'] == '/' }
这会将整个 /dev/sda3 哈希分配给 $root_partition
,相当于 {"/dev/sda3" => {"filesystem" .... }}
.
然后使用 stdlib 中的 keys
函数从剩下的单个哈希键中提取设备名称:
$hddname = keys($root_partition)[0]
我正在尝试使用 Puppet facter 获取根分区 (mount => "/")
名称。
当我运行“facter partitions
”时,它显示三个分区。
我想从结果中获取变量 "sda3"。
{
/dev/sda1 => {
size => "1.00 MiB",
size_bytes => 1048576
},
/dev/sda2 => {
filesystem => "ext2",
mount => "/boot",
size => "477.00 MiB",
size_bytes => 500170752,
uuid => "8345d60e-e09a-4723-b5a6-149f4002706d"
},
/dev/sda3 => {
filesystem => "ext4",
mount => "/",
size => "49.71 GiB",
size_bytes => 53376712704,
uuid => "a1330fb2-7f13-417e-8908-813b1fdae911"
},
我尝试了 $hddname = $facts['partitions']['mount'] == "/"
,但出现错误。
你们有什么想法吗?
在处理散列和数组时,您可能需要 Puppet Iteration and loops 功能。该页面链接到一些有用的功能,将帮助您找到所需的功能。
首先你需要过滤输入:
$root_partition = $facts['partitions'].filter |$device, $partition| { $partition['mount'] == '/' }
这会将整个 /dev/sda3 哈希分配给 $root_partition
,相当于 {"/dev/sda3" => {"filesystem" .... }}
.
然后使用 stdlib 中的 keys
函数从剩下的单个哈希键中提取设备名称:
$hddname = keys($root_partition)[0]