
當我執行木偶應用時,出現錯誤:
Warning: Scope(Mod::Cl[title]): Can't load '/tmp/file.yaml' File does not exist!
Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Operator '[]' is not applicable to an Undef Value.
我指定 loadyaml 是 stdlib 模組的函數
但是,我想在定義資源之前執行文件資源
有人可以幫我嗎?
類別 mod::princ ( 檔案 { '/tmp/file.yaml': 確保=>文件, 擁有者 => '根', 組 => '根', 模式=>“0644”, 來源=>“puppet:///modules/othermod/file.yaml”, 之前 => Mod::Cl["標題"], }-> Mod::Cl{ “標題” : tmp_file =>“/tmp/file.yaml”, } } 定義 mod::cl ( 字串 $tmp_file, ){ $tmp = loadyaml("$tmp_file") $tmp[var].each |整數 $i,雜湊[字串,字串] $var| { $mark=$var['標記'] } }
答案1
根據我對木偶的經驗,「之前」/「需要」和排序(->)之類的東西不能很好地協同工作。嘗試刪除排序,因為可能沒有建立文件...
答案2
正如傀儡函數呼叫中所指定的參考頁,函數在編譯時調用,因此無論順序如何,函數都會在模組執行之前調用。