# Environment variables template file not running

**URL:** <https://discourse.chef.io/t/environment-variables-template-file-not-running/9571>\
**Category:** Chef Infra (archive)\
**Created:** [October 3, 2016, 11:28am UTC](https://discourse.chef.io/t/environment-variables-template-file-not-running/9571 "2016-10-03T11:28:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![v\_chef](https://avatars.discourse-cdn.com/v4/letter/v/977dab/32.png) [@v\_chef](https://discourse.chef.io/u/v_chef)\
**Post date:** [October 3, 2016, 11:28am UTC](https://discourse.chef.io/t/environment-variables-template-file-not-running/9571/1 "2016-10-03T11:28:40Z")

</div>

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

# ) end attribute file: export.erb

export WAS\_INSTALL\_ROOT=\<%= @was\_dir %\>  
chown -R wasuser:wasuser \<%= @was\_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.

---

<div class="post-metadata">

**Author:** ![joerg.herzinger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/joerg.herzinger/32/1514_2.png) [@joerg.herzinger](https://discourse.chef.io/u/joerg.herzinger)\
**Post date:** [October 3, 2016, 11:32am UTC](https://discourse.chef.io/t/environment-variables-template-file-not-running/9571/2 "2016-10-03T11:32:13Z")

</div>

This actually has nothing to do with Chef but with Bash/Shell. Please consult the according documentation about this: [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect\_03\_01.html](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html)

---

<div class="post-metadata">

**Author:** ![v\_chef](https://avatars.discourse-cdn.com/v4/letter/v/977dab/32.png) [@v\_chef](https://discourse.chef.io/u/v_chef)\
**Post date:** [October 3, 2016, 11:36am UTC](https://discourse.chef.io/t/environment-variables-template-file-not-running/9571/3 "2016-10-03T11:36:36Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![joerg.herzinger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/joerg.herzinger/32/1514_2.png) [@joerg.herzinger](https://discourse.chef.io/u/joerg.herzinger)\
**Post date:** [October 3, 2016, 11:56am UTC](https://discourse.chef.io/t/environment-variables-template-file-not-running/9571/4 "2016-10-03T11:56:31Z")

</div>

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](https://docs.chef.io/resource_execute.html)

---

<div class="post-metadata">

**Author:** ![Tensibai](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tensibai/32/29_2.png) [@Tensibai](https://discourse.chef.io/u/Tensibai)\
**Post date:** [October 3, 2016, 2:09pm UTC](https://discourse.chef.io/t/environment-variables-template-file-not-running/9571/5 "2016-10-03T14:09:27Z")

</div>

> [@v\_chef](#):
>
> **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**
> 
> )

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.
