【发布时间】:2021-04-20 20:53:37
【问题描述】:
我有一个模板文件
#fileName: test.properties.erb
<% if @env == 'STAGING' && node['hostname'] =~ /^staging/ %>
somekey=node['hostname']
<% else %>
somekey=defaultNode
<% end %>
我的食谱如下
template ("test.properties") do
source 'test.properties.erb'
variables(
env: "STAGING"
)
end
我想和 REGEX 检查一起执行 && 操作
当我在 erb 文件中使用以下内容时,它适用于 &&
<% if @env = 'STAGING' && node['hostname'].include?('staging-01') %>
...
我想应用一个正则表达式并检查主机名是否以字符串 staging 开头
假设我有staging-01、staging-02 并申请两者
【问题讨论】:
-
node['hostname']是字符串吗? -
是的,是一个字符串,返回主机名
-
所以这个有逻辑的文件就是erb文件。
标签: ruby chef-infra