I am stuck with a situation where I have created a templates/test.sh.erb file with below content:
#!/bin/bash
ls -ltr <%= "#{tomcat_home}/instance1/bin" %>
ls -ltr <%= "#{tomcat_home}/instance1/conf" %>
For this erb file, I wanted to pass "tomcat_home" which can be either "/opt/tomcat" or "/opt/apacheTomcat". This data I am parsing using if else condition which is returning me tomcat home either one of this path.
eg: tomcat_home="/opt/tomcat"
I wanted to create the test.sh file at /tmp location on server in which I wanted to replace the tomcat_home variable dynamically whenever it will create the test.sh file . template resource logic:
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
Desired output I am expecting when template resource will run:
#!/bin/bash
ls -ltr /opt/tomcat/instance1/bin
ls -ltr /opt/tomcat/instance1/conf