Class: Puppet::Provider::Exec
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::Exec
- Includes:
- Util::Execution
- Defined in:
- lib/vendor/puppet/provider/exec.rb
Constant Summary
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows
Constants included from Util::Docs
Instance Attribute Summary
Attributes inherited from Puppet::Provider
Attributes included from Util::Docs
Instance Method Summary collapse
Methods included from Util::Execution
Methods inherited from Puppet::Provider
#<=>, #clear, command, #command, commands, declared_feature?, default?, defaultfor, #get, #initialize, initvars, instances, make_command_methods, mk_resource_methods, mkmodelmethods, #name, optional_commands, #set, specificity, supports_parameter?, #to_s
Methods included from Util::Logging
#clear_deprecation_warnings, #deprecation_warning, #send_log
Methods included from Util
absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Methods included from Util::Warnings
clear_warnings, notice_once, warnonce
Methods included from Confiner
#confine, #confine_collection, #suitable?
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Constructor Details
This class inherits a constructor from Puppet::Provider
Instance Method Details
#extractexe(command) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vendor/puppet/provider/exec.rb', line 68 def extractexe(command) if command.is_a? Array command.first elsif match = /^"([^"]+)"|^'([^']+)'/.match(command) # extract whichever of the two sides matched the content. match[1] or match[2] else command.split(/ /)[0] end end |
#run(command, check = false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vendor/puppet/provider/exec.rb', line 7 def run(command, check = false) output = nil status = nil dir = nil checkexe(command) if dir = resource[:cwd] unless File.directory?(dir) if check dir = nil else self.fail "Working directory '#{dir}' does not exist" end end end dir ||= Dir.pwd debug "Executing#{check ? " check": ""} '#{command}'" begin # Do our chdir Dir.chdir(dir) do environment = {} environment[:PATH] = resource[:path].join(File::PATH_SEPARATOR) if resource[:path] if envlist = resource[:environment] envlist = [envlist] unless envlist.is_a? Array envlist.each do |setting| if setting =~ /^(\w+)=((.|\n)+)$/ env_name = $1 value = $2 if environment.include?(env_name) || environment.include?(env_name.to_sym) warning "Overriding environment setting '#{env_name}' with '#{value}'" end environment[env_name] = value else warning "Cannot understand environment setting #{setting.inspect}" end end end withenv environment do Timeout::timeout(resource[:timeout]) do output, status = Puppet::Util::SUIDManager. run_and_capture(command, resource[:user], resource[:group]) end # The shell returns 127 if the command is missing. if status.exitstatus == 127 raise ArgumentError, output end end end rescue Errno::ENOENT => detail self.fail detail.to_s end return output, status end |
#validatecmd(command) ⇒ Object
79 80 81 82 83 |
# File 'lib/vendor/puppet/provider/exec.rb', line 79 def validatecmd(command) exe = extractexe(command) # if we're not fully qualified, require a path self.fail "'#{command}' is not qualified and no path was specified. Please qualify the command or specify a path." if !absolute_path?(exe) and resource[:path].nil? end |