Hi,
I have created a recipe to create a template file for environment variables set and changing dir permission in unix and run it at after creating. Below is my recipe.
Recipe file: env_variables.rb
was_dir=/opt/middleware/websphere/70
template ‘/tmp/export_env.sh’ do
source 'export.erb’
owner 'wasuser’
group 'wasuser’
mode '0777’
variables(
# a_list: a,
was_dir: was_product_dir
Now, after running chef-client tempalte file /tmp/export_env.sh is getting generated in my server but how do I run shell script file “/tmp/export_env.sh” immediately after template getting created. After generating template file I do not want to run that file “/tmp/export_env.sh” manually in order to set env variable and change permission.
Actually the issue here is if I have kept the attributes in .erb file and if I run chef-client as root generate template file should have been executed by default or do I need to write something to make it run?
If it should be running by default what is the issue in my recipe and if I need to write something to make it running can you suggest .
I am still not entirely sure what you use case is. What I can tell you is that chef does not “run” anything by rendering a template. The template resource only places the file on your disk and sets permissions etc. If you want to run the script you will have to use the execute resource: https://docs.chef.io/resource_execute.html
I assume your problem is in the bold names above, was_product_dir is not defined and resolve to nil, so your template render with an empty value.
Edit for the second part of your question:
execute "/tmp/export_env.sh" do
action :nothing
end
template "/tmp/export_env.sh" do
[...]
notifies :run,"execute[/tmp/export_env.sh]", :immediately
end
But this won't have the effect you wish it to do, as the export will stay only for the time the exeute resource run.
I assume this is a XY problem, part of something larger (probably installing websphere) but without more insight it needs divination skills to give correct advices.