puppet 模块代码中 puppet hiera() 和 lookup() 的区别
Difference between puppet hiera() and lookup() in puppet module code
我正在尝试从 hiera() 切换到 lookup() 但它不起作用。
我曾经有以下代码行:
if (hiera("ntp::enabled",0) == 1 ){
它工作正常。
用 lookup 替换 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() 调用。
我不是木偶专家,但看着 the documentation for lookup 它似乎需要一组不同于 hiera()
调用的参数:
lookup( <NAME>, [<VALUE TYPE>], [<MERGE BEHAVIOR>], [<DEFAULT VALUE>] )
如果您想使用位置选项提供默认值,您还需要填写 <VALUE TYPE>
和 <MERGE BEHAVIOR>
的值。看起来另一种方法是提供参数的散列而不是列表。如果您继续阅读这些文档,您会看到调用该函数的另一种方法是:
lookup( [<NAME>], <OPTIONS HASH> )
该机制的示例可能如下所示 :
lookup({"name" => "some::thing", "default_value" => "default"})
我正在尝试从 hiera() 切换到 lookup() 但它不起作用。 我曾经有以下代码行:
if (hiera("ntp::enabled",0) == 1 ){
它工作正常。
用 lookup 替换 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() 调用。
我不是木偶专家,但看着 the documentation for lookup 它似乎需要一组不同于 hiera()
调用的参数:
lookup( <NAME>, [<VALUE TYPE>], [<MERGE BEHAVIOR>], [<DEFAULT VALUE>] )
如果您想使用位置选项提供默认值,您还需要填写 <VALUE TYPE>
和 <MERGE BEHAVIOR>
的值。看起来另一种方法是提供参数的散列而不是列表。如果您继续阅读这些文档,您会看到调用该函数的另一种方法是:
lookup( [<NAME>], <OPTIONS HASH> )
该机制的示例可能如下所示
lookup({"name" => "some::thing", "default_value" => "default"})