2017-02-24 68 views
1

我想使用木偶因素獲得根分區(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 == '/' }你們有什麼想法嗎?

回答

2

你可以直接通過散列符號來訪問這個事實。由於您的問題嚴重意味着您正在使用Facter 3/Puppet 4,因此我將使用該語法。

您只需直接遍歷Facter散列中的鍵即可獲得/dev/md3的值。如果我們儘量減少facter mountpoints散到相關的部分:

{ 
/=> { 
    device => "/dev/md3" 
    } 
} 

那麼我們可以看到,關鍵是mountpoints(你直接訪問該密鑰當您從CLI做facter mountpoints),/device。這裏

$facts['mountpoints']['/']['device'] # /dev/md3 

檢查的詳細信息:因此,利用木偶標準哈希符號與$facts哈希,我們可以訪問該值https://docs.puppet.com/puppet/4.9/lang_facts_and_builtin_vars.html#the-factsfactname-hash

+0

太好了!非常感謝 – Mike