Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set environment variable using saltstack

I am writing some salt stack formulas which will install tomcat package. but after installation I have to set JAVA_HOME in /etc/default/tomcat7 file. Is there any option to set JAVA_HOME? Or is there any option to modify or add JAVA_HOME in environment variable (i.e. in .bashrc or .profile files)?

My pillar.example file will have these details:

    tomcat_version: 7
    java_home: '/usr/lib/jvm/java-7-oracle'
like image 598
Naveen Subramani Avatar asked Jan 16 '14 07:01

Naveen Subramani


1 Answers

As an alternative to setting .bashrc or .profile, you could simply set the JAVA_HOME value directly in /etc/default/tomcat7:

tomcat_configuration:
  file.append:
    - name: /etc/default/tomcat7
    - text: export JAVA_HOME={{ pillar['java_home'] }}

If for some reason file.append is not suitable, salt offers file.replace and (new in 0.18.0) file.blockreplace.

like image 148
Jeff Bauer Avatar answered Sep 30 '22 23:09

Jeff Bauer