diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-05 23:20:45 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-05 23:20:45 +0000 |
| commit | fcc5bae22cb2a0286975cfc0bcab52a2a7f7973d (patch) | |
| tree | 6ebe72a068a216cd56f6938b4d90fe0eaa86671b /lib | |
| parent | 8310c9d18a89e499b63a10e7890d836dcfc86f46 (diff) | |
| download | puppet-fcc5bae22cb2a0286975cfc0bcab52a2a7f7973d.tar.gz puppet-fcc5bae22cb2a0286975cfc0bcab52a2a7f7973d.tar.xz puppet-fcc5bae22cb2a0286975cfc0bcab52a2a7f7973d.zip | |
Adding an "env" parameter to exec, for providing extra environment settings, as requested in #236.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1568 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/puppet/type/exec.rb | 39 | ||||
| -rw-r--r-- | lib/puppet/util/execution.rb | 1 |
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index c5cf81142..442eb311f 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -241,7 +241,9 @@ module Puppet this directory does not exist, the command will fail." validate do |dir| - self.fail("CWD must be a fully qualified path") unless dir + unless dir =~ /^#{File::SEPARATOR}/ + self.fail("CWD must be a fully qualified path") + end end munge do |dir| @@ -264,6 +266,22 @@ module Puppet newvalues(*values) end + newparam(:env) do + desc "Any additional environment variables you want to set for a + command. Note that if you use this to set PATH, it will override + the ``path`` attribute. Multiple environment variables should be + specified as an array." + + validate do |values| + values = [values] unless values.is_a? Array + values.each do |value| + unless value =~ /\w+=/ + raise ArgumentError, "Invalid environment setting '%s'" % value + end + end + end + end + newcheck(:refreshonly) do desc "The command should only be run as a refresh mechanism for when a dependent object is changed. It only @@ -499,6 +517,25 @@ module Puppet env[:PATH] = self[:path].join(":") end + if envlist = self[:env] + envlist = [envlist] unless envlist.is_a? Array + envlist.each do |setting| + if setting =~ /^(\w+)=((.|\n)+)$/ + name = $1 + value = $2 + if env.include? name + warning( + "Overriding environment setting '%s' with '%s'" % + [name, value] + ) + end + env[name] = value + else + warning "Cannot understand env setting '%s'" % setting + end + end + end + withenv env do # The user and group default to nil, which 'asuser' # handlers correctly diff --git a/lib/puppet/util/execution.rb b/lib/puppet/util/execution.rb index 67b5ed692..467cd3f52 100644 --- a/lib/puppet/util/execution.rb +++ b/lib/puppet/util/execution.rb @@ -8,6 +8,7 @@ module Puppet::Util::Execution hash.each do |name, val| name = name.to_s oldvals[name] = ENV[name] + ENV[name] = val end yield |
