【发布时间】:2021-08-09 14:55:29
【问题描述】:
我遇到了一种情况,我创建了一个包含以下内容的模板/test.sh.erb 文件:
#!/bin/bash
ls -ltr <%= "#{tomcat_home}/instance1/bin" %>
ls -ltr <%= "#{tomcat_home}/instance1/conf" %>
对于这个 erb 文件,我想传递“tomcat_home”,它可以是“/opt/tomcat”或“/opt/apacheTomcat”。我正在使用 if else 条件解析此数据,该条件将我的 tomcat 返回此路径之一。
eg: tomcat_home="/opt/tomcat"
我想在服务器上的 /tmp 位置创建 test.sh 文件,我想在创建 test.sh 文件时动态替换 tomcat_home 变量。 模板资源逻辑:
template "/tmp/test.sh" do
source 'test.sh.erb' # <-- this is your directory in files/default/local_directory
owner 'tomcat'
group 'tomcat'
mode '0755'
action :create
end
当模板资源运行时我期望的输出:
#!/bin/bash
ls -ltr /opt/tomcat/instance1/bin
ls -ltr /opt/tomcat/instance1/conf
【问题讨论】:
标签: ruby chef-infra