我有一个木偶清单,看起来像这样:
$webapp_list = lookup('webapps', Hash, 'hash')
$webapp_list.each | $app_name, $app_info| {
$app_port = $app_info[port]
$app_description = $app_info[description]
$app_settings = [ $app_info[settings] ]
和 hiera 代码:
webapps:
webapp-template:
port: 5001
description: "Webapp Description"
live: false
settings:
FLASK_APP: appname.py
MAIL_USERNAME: email@example.com
MAIL_PASSWORD: <extra strong password>
我正在使用如下所示的 erb 模板:
<% @app_settings.each do |settingKey, settingValue| -%>
export <%= settingKey -%>='<%= settingValue -%>'
<% end %>
尝试生成如下所示的文件:
export FLASK_APP=appname.py
export MAIL_USERNAME=email@example.com
export MAIL_PASSWORD=<extra strong password>
我已经尝试了各种不同的方法(这只是最新的(,这些方法会导致 puppet 出错:
Info: Using configured environment 'special'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Failed to parse template webapps/settings.conf.erb:
Filepath: /etc/puppet/code/modules/webapps/templates/settings.conf.erb
Line: 2
Detail: undefined method `each' for nil:NilClass
at /etc/puppet/code/modules/webapps/manifests/init.pp:40:18 on node web.home
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
或生成如下所示的文件:
export {"FLASK_APP"=>"appname.py", "MAIL_USERNAME"=>"email@example.com", "MAIL_PASSWORD"=>"<extra strong password>"}=''
我知道答案在某种程度上与我如何处理数组和哈希有关,并且解决方案正盯着我的脸,但我目前对下一步行动一无所知。
我已经找到了解决方案。这主要是因为我的yaml文件我有其他没有"设置"部分的网络应用程序,导致它倒塌。我的最终代码可以在下面看到。
希拉:
webapps:
webapp-template:
port: 5001
description: "Webapp Description"
live: false
settings:
FLASK_APP: appname.py
MAIL_USERNAME: email@example.com
MAIL_PASSWORD: <extra strong password>
傀儡清单:
$webapp_list = lookup('webapps', Hash, 'hash')
$webapp_list.each | $app_name, $app_info| {
$app_port = $app_info[port]
$app_description = $app_info[description]
$app_settings = $app_info[settings]
Settings.conf.erb:
<% @app_settings.each do |key,value| -%>
export <%= key %>='<%= value %>'
<% end -%>