summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/type/exec.rb39
-rw-r--r--lib/puppet/util/execution.rb1
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