[chef] Setting Environment Variables


Chronological Thread 
  • From: Brian Jakovich < >
  • To:
  • Subject: [chef] Setting Environment Variables
  • Date: Sat, 20 Aug 2011 13:09:18 -0400

How do I go about setting environment variables in chef? I've tried several methods such as adding them to a template and then sourcing it. Adding them to attributes. I'm out of ideas...

## Problem

The JENKINS_HOME environment variable doesn't get set. It should however be set using the template "default_jenkins.erb"
whenever I go into the instance and echo $JENKINS_HOME it does not return anything

## Current status

Currently it successfully takes the jenkins war from the remote location and places it into the webapps directory of Tomcat. When I go to the http://PublicDNS:8080/jenkins Jenkins is running. (It does however complain about not being able to create .jenkins directory, AKA Jenkins Home, and suggests that there is a problem with its permissions)

## default recipe

# Setting local variables
jenkinsWar = node[:jenkins][:war]
webapp_dir = node["tomcat"]["webapp_dir"]
tomcat_user = node["tomcat"]["user"]
tomcat_group = node["tomcat"]["group"]

# Getting the Jenkins.war and putting it into the tomcat webapps directory
remote_file "/#{webapp_dir}/#{jenkinsWar}" do
 source "#{node[:jenkins][:url]}"
 mode "0644"
 owner "root"
 group "root"
end

# Setting Jenkins configuration
template "/etc/default/jenkins" do
  source "default_jenkins.erb"
  owner "root"
  group "root"
  mode "0644"
  notifies :restart, resources(:service => "tomcat")
end


## default_jenkins.erb

# Set Jenkins home variable. This will tell Jenkins where to find it's jobs/plugins/etc
JENKINS_HOME=<%= node[:jenkins][:home] %>

## default attribute

default[:jenkins][:war] = "jenkins.war"
default[:jenkins][:home] = "/var/lib/jenkins"
default[:jenkins][:url] = "https://s3.amazonaws.com/cookbook-resources/#{node[:jenkins][:war]}"



Archive powered by MHonArc 2.6.16.

§