迭代Puppet中的哈希键/值

Dex*_*spi 5 puppet

我正在尝试用Puppet更新ASP.NET web.config中的任意appsettings列表(用于部署目的)而且我处于两难境地,主要是因为我是一个真正的傀儡n00b.

我有这个yaml文件(hiera)

---
appSettings:
  setting1: "hello"
  setting2: "world!"
  setting3: "lalala"
Run Code Online (Sandbox Code Playgroud)

setting[x]可以任意跨越的数量(一个appSetting),我想循环遍历散列键/值来更新appSetting/addweb.config中的相应内容(使用execpowershell)问题是我已经搜索了如何迭代的高低上键和值.

我遇到过create_resources,当然这会通过一组预先确定的密钥迭代哈希.同样,密钥名称在清单中是未知的(因此迭代键/值对).

任何指导表示赞赏.

编辑:看起来有一个keys()我可以在哈希上使用的函数并迭代,然后使用hiera_hash('appSettings')来获取哈希值并迭代值.

Dex*_*spi 8

好吧,我刚确认你可以在你的清单中做什么:

define updateAppSetting {
    # get the hashes again because outside vars aren't visible here
    $appSettings = hiera_hash('appSettings')

    # $name is the key $appsettingValue is the value
    $appsettingValue = $appSettings[$name]

    # update the web.config here!
}

$appSettings = hiera_hash('appSettings')    

# the keys() function returns the array of hash keys
$appSettingKeys = keys($appSettings)

# iterate through each appSetting key
updateAppSetting{$appSettingKeys:}
Run Code Online (Sandbox Code Playgroud)