lib/puppet/util/suidmanager.rb in puppet-2.7.26 vs lib/puppet/util/suidmanager.rb in puppet-3.0.0.rc4

- old
+ new

@@ -163,11 +163,36 @@ Process.initgroups(pwent.name, pwent.gid) end module_function :initgroups - def run_and_capture(command, new_uid=nil, new_gid=nil) - output = Puppet::Util.execute(command, :failonfail => false, :combine => true, :uid => new_uid, :gid => new_gid) + # Run a command and capture the output + # Parameters: + # [command] the command to execute + # [new_uid] (optional) a userid to run the command as + # [new_gid] (optional) a groupid to run the command as + # [options] (optional, defaults to {}) a hash of option key/value pairs; currently supported: + # :override_locale (defaults to true) a flag indicating whether or puppet should temporarily override the + # system locale for the duration of the command. If true, the locale will be set to 'C' to ensure consistent + # output / formatting from the command, which makes it much easier to parse the output. If false, the system + # locale will be respected. + # :custom_environment (default {}) -- a hash of key/value pairs to set as environment variables for the duration + # of the command + def run_and_capture(command, new_uid=nil, new_gid=nil, options = {}) + + # specifying these here rather than in the method signature to allow callers to pass in a partial + # set of overrides without affecting the default values for options that they don't pass in + default_options = { + :override_locale => true, + :custom_environment => {}, + } + + options = default_options.merge(options) + + output = Puppet::Util::Execution.execute(command, :failonfail => false, :combine => true, + :uid => new_uid, :gid => new_gid, + :override_locale => options[:override_locale], + :custom_environment => options[:custom_environment]) [output, $CHILD_STATUS.dup] end module_function :run_and_capture end