【问题标题】:Puppet - The function 'hiera_array' is deprecated in favor of using 'lookup'Puppet - 函数 'hiera_array' 已弃用,取而代之的是使用 'lookup'
【发布时间】:2018-06-04 15:34:57
【问题描述】:

我有一个木偶问题。 (我用的是5.1.0版本)

在此路径中:C:\ProgramData\PuppetLabs\code\environments\production\manifests 我有文件:site.pp 此文件 (/etc/puppetlabs/puppet/manifests/site.pp) 是代理连接到主服务器并请求更新配置时使用的主要入口点。

这是现在文件的内容:

node default {
  # This is where you can declare classes for all nodes.
  # Example:
  #   class { 'my_class': }
  #hiera_include('classes')
  include(hiera_array("classes", ))
}

但是当我使用 puppet apply 命令运行 puppet 时:

"C:\Program Files\Puppet Labs\Puppet\bin\puppet" 应用 C:\ProgramData\PuppetLabs\code\environments\production\manifests\site.pp

我收到此错误:

Warning: The function 'hiera_array' is deprecated in favor of using 'lookup'. See https://docs.puppet.com/puppet/5.1/referenc
e/deprecated_language.html
   (file & line not available)
Error: Function lookup() did not find a value for the name 'classes'

所以我把site.pp代码改成:

node default {
  # This is where you can declare classes for all nodes.
  # Example:
  #   class { 'my_class': }
  #hiera_include('classes')
  include(lookup('classes', {merge => unique}, ))
}

(因为我找到了这个文档:https://puppet.com/docs/puppet/5.1/hiera_migrate_functions.html

现在我只得到这个错误:

Error: Function lookup() did not find a value for the name 'classes'

我不确定如何修复它,因为该代码在一个月前使用相同的应用命令运行。

你能帮帮我吗?

谢谢!

【问题讨论】:

  • 查找代码应该是lookup('classes', Array[String], 'unique').include。但这并不能完全解决您的问题,因为它源于您尚未提供相关信息的 Hiera 配置和数据组织问题。
  • @MattSchuchard,OP 对lookup() 的调用很好,因为他(仍然)收到的错误消息确实支持。该函数有multiple alternative signatures,并且OP的使用匹配其中之一。
  • @JohnBollinger 我可能不清楚。我并不是要暗示它导致了错误,而是它在清晰度、类型检查等方面不是最佳的。我仍然坚持我的说法,即错误的来源来自 hiera 配置/数据组织。这个问题需要更多相关信息。

标签: puppet devops


【解决方案1】:

我得到这个错误:

Warning: The function 'hiera_array' is deprecated in favor of using 'lookup'. See https://docs.puppet.com/puppet/5.1/referenc e/deprecated_language.html (file & line not available)
Error: Function lookup() did not find a value for the name 'classes'

更正:您会收到警告错误。该错误是单独的,但表明 Puppet 正在处理它通过在内部委派新的 lookup() 函数来警告的情况。

于是我把site.pp代码改成了:

node default {
  # This is where you can declare classes for all nodes.
  # Example:
  #   class { 'my_class': }
  #hiera_include('classes')
  include(lookup('classes', {merge => unique}, ))
}

是的,这是解决警告的一种非常好的和自然的方法,看起来它在这方面是成功的。但同样,错误是分开的。这与您的清单无关,而是与您的数据有关。正如它所说,查找关键“类”的尝试失败了。没有找到这样的密钥。在这种情况下,您没有为 lookup() 提供要返回的默认值,因此会发生错误。

我不确定如何修复它,因为该代码在一个月前使用相同的应用命令运行。

如果 Puppet 曾经运行相同的代码而没有发出错误,那么从那时到现在发生变化的是数据。然而,这可能是因为您现在以不同的用户身份运行 Puppet。不同的普通用户都有自己的数据(和manifest)默认位置,这些都与系统运行Puppet时使用的位置不同。

【讨论】:

    猜你喜欢
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多