我正在尝试从hiera()切换到lookup(),但是它不起作用。 我以前有以下代码行:
if (hiera("ntp::enabled",0) == 1 ){
它正常工作。
简单地将hiera替换为查找后:
if (lookup("ntp::enabled",0) == 1 ){
我遇到了一个大错误:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, 'lookup' expects one of:
(NameType = Variant[String, Array[String]] name, ValueType = Type value_type?, MergeType = Variant[String[1], Hash[String, Scalar]] merge?)
rejected: parameter 'value_type' expects a ValueType = Type value, got Integer
(NameType = Variant[String, Array[String]] name, Optional[ValueType] value_type, Optional[MergeType] merge, DefaultValueType = Any default_value)
rejected: expects 4 arguments, got 2
(NameType = Variant[String, Array[String]] name, ValueType = Type value_type?, MergeType = Variant[String[1], Hash[String, Scalar]] merge?)
rejected: parameter 'value_type' expects a ValueType = Type value, got Integer
(OptionsWithName = Struct[{'name' => NameType = Variant[String, Array[String]], 'value_type' => Optional[ValueType = Type], 'default_value' => DefaultValueType = Any, 'override' => Optional[Hash[String, Any]], 'default_values_hash' => Optional[Hash[String, Any]], 'merge' => Optional[MergeType = Variant[String[1], Hash[String, Scalar]]]}] options_hash, BlockType = Callable[NameType = Variant[String, Array[String]]] block?)
rejected: expects 1 argument, got 2
(Variant[String, Array[String]] name, OptionsWithoutName = Struct[{'value_type' => Optional[ValueType = Type], 'default_value' => DefaultValueType = Any, 'override' => Optional[Hash[String, Any]], 'default_values_hash' => Optional[Hash[String, Any]], 'merge' => Optional[MergeType = Variant[String[1], Hash[String, Scalar]]]}] options_hash, BlockType = Callable[NameType = Variant[String, Array[String]]] block?)
rejected: parameter 'options_hash' expects an OptionsWithoutName = Struct[{'value_type' => Optional[ValueType = Type], 'default_value' => DefaultValueType = Any, 'override' => Optional[Hash[String, Any]], 'default_values_hash' => Optional[Hash[String, Any]], 'merge' => Optional[MergeType = Variant[String[1], Hash[String, Scalar]]]}] value, got Integer (file: /etc/puppetlabs/code/environments/sandbox/modules/ntp_mycompany/manifests/init.pp, line: 38, column: 5) on node mybox.mycompany.com
可能我错过了一些简单的东西,但我认为可以简单地用较新的lookup()调用替换不推荐使用的hiera()调用。
答案 0 :(得分:1)
我不是木偶专家,但是看着the documentation for lookup似乎需要的参数集与hiera()
调用不同:
lookup( <NAME>, [<VALUE TYPE>], [<MERGE BEHAVIOR>], [<DEFAULT VALUE>] )
如果要使用位置选项提供默认值,则还需要填写<VALUE TYPE>
和<MERGE BEHAVIOR>
的值。看起来,替代方法是提供参数的哈希值而不是列表。如果您继续阅读这些文档,则会看到另一种调用函数的方法:
lookup( [<NAME>], <OPTIONS HASH> )
该机制的一个例子可能是like this:
lookup({"name" => "some::thing", "default_value" => "default"})