puppet - Cannot parse hash from hiera into erb template
问题描述
I have a puppet manifest that looks like this:
$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] ]
and hiera code:
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>
I am using an erb template that looks like this:
<% @app_settings.each do |settingKey, settingValue| -%>
export <%= settingKey -%>='<%= settingValue -%>'
<% end %>
to try and produce a file that looks like this:
export FLASK_APP=appname.py
export MAIL_USERNAME=email@example.com
export MAIL_PASSWORD=<extra strong password>
I have tried a variety of different approaches (this is simply the latest) which result in either an error from 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
or results in a file that looks like this:
export {"FLASK_APP"=>"appname.py", "MAIL_USERNAME"=>"email@example.com", "MAIL_PASSWORD"=>"<extra strong password>"}=''
I know the answer is somehow to do with how I am handling arrays and hashes and that the solution is staring me in the face, but I am currently clueless as to my next move.
解决方案
我找到了解决方案。这主要是因为我的 yaml 文件有其他没有“设置”部分的 web 应用程序导致它崩溃。我的最终代码如下所示。
希拉:
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]
设置.conf.erb:
<% @app_settings.each do |key,value| -%>
export <%= key %>='<%= value %>'
<% end -%>
推荐阅读
- docker - 从主机控制台分离容器
- ios - Cell is in the center of collection view when there is only one cell
- android - setOnClickListener 返回一个空异常
- powerbi - Why are embedded reports not loading after longer period of being logged in?
- python - 如何将python中的图像保存在不同的目录中?
- java - JFrame 窗口不显示
- java - 为什么在解析 JSON 的方法中设置字符串时返回 null?(底部返回全部为空)
- hbase - 通过 NiFi 将 HBase 数据库转储到不同的集群
- python - Get the contents of a specific attribute in span tag
- lets-encrypt - 为什么 Let's Encrypt 颁发的证书在一个小时左右无效?