我正在尝试使用 Puppet 来更新 ASP.NET web.config 中的任意应用程序设置列表(用于部署目的),但我陷入了困境,主要是因为我是一个真正的 puppet 专家。
我有这个 yaml 文件(hiera)
---
appSettings:
setting1: "hello"
setting2: "world!"
setting3: "lalala"
的数量setting[x]
可以任意跨越(一个应用程序设置),我想循环遍历哈希键/值来更新相应的appSetting/add
在 web.config 中(使用exec
使用powershell)问题是我已经搜索了如何迭代keys and values.
我碰到create_resources
当然,这会使用一组预先确定的键来迭代哈希的哈希。同样,清单中的键名称是未知的(因此迭代键/值对)。
任何指导表示赞赏。
编辑:看起来有一个keys()
我可以在哈希上使用函数并对其进行迭代,然后使用 hiera_hash('appSettings') 来获取哈希并迭代值。
好的,我刚刚确认了您可以在清单中执行的操作:
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:}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)