Hiera - 将结果分解为行项目

问题描述 投票:0回答:1

我正在使用 puppet 3.6.2 并尝试使用 hiera 中的数据作为 Windows 修补解决方案。我处于断开网络状态,无法使用 WSUS。

我有一个文件 patch.yml,它看起来像这样:

windows::patches:
  - Firefox-Setup-119.0b9.exe
  - KB5007255-x64.msu
  - KB5008285-x64.msu
  - KB5008897-x64.msu
  - KB5009595-x64.msu
  - KB5010395-x64.msu
  - KB5011560-x64.msu
  - KB5012144-x64.msu

我的 windowspatches.pp 文件如下所示:

class profile::windowspatches (
  $filename = hiera("windows::patches")
)
{

  include stdlib

notify{ "$filename": 
  message => $filename
}


#$downloadUrl = "http://server1/Microsoft/"

#package {$patches:
#   ensure => "installed",
#   source => "$downloadUrl+$filename"
#   
#   }

}

我正在研究我的想法,并注释掉其他操作。

目前的结果如下所示:

Firefox-Setup-119.0b9.exeKB5007255-x64。 msuKB5008285-x64.msuKB5008897-x64.msuKB5009595-x64.msuKB5010395-x64.msuKB5011560 -x64.msuKB5012144-x64.msuKB5012670-x64.msuKB5013616-x64.msuKB5014011-x64.msuKB50 14746-x64.msuKB5015877-x64.msuKB5016683-x64.msuKB5017365-x64.msuKB5018476-x64.ms uKB5020010-x64.msuKB5020608-x64.msuKB5020902-x64.msuKB5021296-x64.msuKB5022346-x 64.msuKB5022508-x64.msuKB5022894-x64.msuKB5023764-x64.msuKB5025288-x64.msuKB5026 409-x64.msuKB5027109-x64.msuKB5027282-x64.msuKB5028223-x64.msuKB5028974-x64.msuK B5029304-x64.msuKB5029942-x64.msuKB5030287-x64.msuKB5031407-x64.msu(noop)

我已经厌倦了 $filename = hiera("windows::patches"),这给了我相同的结果。

我不确定我错过了什么。我知道我有旧版本的 puppet,无法升级。

puppet hiera
1个回答
0
投票

您正在提供一个数组,并且您需要迭代该数组。

就这样(还有 2 条额外的建议):

$filename = lookup("windows::patches", Array, 'first', [])  # hiera command is deprecated
$download_url = "http://server1/Microsoft/"  # no CamelCase with puppet

$filename.each | $patch | {
  ensure => installed,
  source => "${download_url}${patch}";
}
  1. 根据 puppet 语言风格指南,您不应使用 CamelCase 变量。因此我从
    downloadUrl
    切换到
    download_url
    https://www.puppet.com/docs/puppet/8/style_guide.html#variable-format
  2. hiera
    命令相当古老,您应该使用
    lookup
    hiera
    在 Puppet 7 中已弃用,并从 Puppet 8 中删除:https://www.puppet.com/docs/puppet/8/hiera_automatic.html
© www.soinside.com 2019 - 2024. All rights reserved.