Kin*_*ook 3 templates nginx conditional-statements chef-infra
使用Chef,只有满足条件,才能从模板插入文本块吗?
假设我们有一个属性:
node["webapp"]["run"] = "true"
Run Code Online (Sandbox Code Playgroud)
如果webapp为true,我们只想在sites-enabled/app.conf中的nginx .conf中输入一个条目,如下所示:
#The nginx-webapp.conf.erb template file
SOME WORKING NGINX CONFIG STUFF
<% if node["webapp"]["run"]=="true" -%>
location /webapp {
try_files $uri @some_other_location;
}
<% end -%>
SOME OTHER WORKING NGINX CONFIG STUFF
Run Code Online (Sandbox Code Playgroud)
就目前而言,条件文本没有错误,它只是永远不会出现.我已经仔细检查了模板是否可以通过以下方式查看节点属性:
<%= node["webapp"]["run"] %>
Run Code Online (Sandbox Code Playgroud)
哪个DID将文本"true"插入配置文件中.
我在Chef和erb模板中看到过.如何使用布尔代码块,我可以插入看似只是带有来自节点的评估变量的文本.
我试过换到
<% if node[:webapp][:run]=="true" -%>
TEXT
<% end -%>
Run Code Online (Sandbox Code Playgroud)
无济于事.
我有什么想法我做错了吗?谢谢!
编辑:
根据Psyreactor的回答,在模板本身我停止尝试评估字符串"true",而是使用它:
SOME WORKING NGINX CONFIG STUFF
<% if node["webapp"]["run"] -%>
location /webapp {
try_files $uri @some_other_location;
}
<% end -%>
SOME OTHER WORKING NGINX CONFIG STUFF
Run Code Online (Sandbox Code Playgroud)
如果节点属性设置为"true",则可以在配置文件中正确插入文本块!我想我只是假设它仍然是一个需要被评估的字符串.
假设你有一个属性
node[:test][:bool] = true
Run Code Online (Sandbox Code Playgroud)
在模板中必须这样做
<% If node[:apache][:bool] -%>
ServerAlias ??<% = node[:apache][:aliasl]%>
<% End -%>
Run Code Online (Sandbox Code Playgroud)
另一种选择是检查属性是否为null
<% Unless node [:icinga][:core][:server_alias].nil? %>
ServerAlias ??<% = node[:icinga][:core][:server_alias]%>
<% End%>
Run Code Online (Sandbox Code Playgroud)
我希望能帮助你.
对不起我的英语祝福
| 归档时间: |
|
| 查看次数: |
2480 次 |
| 最近记录: |