diff --git a/lib/puppet/provider/exec.rb b/lib/puppet/provider/exec.rb index 2257077f3b5..34f2dabdbb4 100644 --- a/lib/puppet/provider/exec.rb +++ b/lib/puppet/provider/exec.rb @@ -102,6 +102,6 @@ def extractexe(command) def validatecmd(command) exe = extractexe(command) # if we're not fully qualified, require a path - self.fail _("'%{exe}' is not qualified and no path was specified. Please qualify the command or specify a path.") % { exe: exe } if !absolute_path?(exe) and resource[:path].nil? + self.fail _("'%{exe}' is not qualified and no path was specified. Please qualify the command or specify a path.") % { exe: exe } if !absolute_path?(exe) && (resource[:path].nil? || resource[:path].empty?) end end diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 57c99416f94..6d5ae668daf 100644 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -223,7 +223,9 @@ def sync newparam(:path) do desc "The search path used for command execution. Commands must be fully qualified if no path is specified. Paths - can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list." + can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list. Defaults to the `path` fact." + + defaultto Puppet.runtime[:facter].value('path') # Support both arrays and colon-separated fields. def value=(*values) diff --git a/spec/unit/provider/exec/posix_spec.rb b/spec/unit/provider/exec/posix_spec.rb index 857b4d8adcf..5bcc28ff354 100644 --- a/spec/unit/provider/exec/posix_spec.rb +++ b/spec/unit/provider/exec/posix_spec.rb @@ -16,10 +16,7 @@ def make_exe describe "#validatecmd" do it "should fail if no path is specified and the command is not fully qualified" do - expect { provider.validatecmd("foo") }.to raise_error( - Puppet::Error, - "'foo' is not qualified and no path was specified. Please qualify the command or specify a path." - ) + expect(provider.validatecmd('foo')).to eq(nil) end it "should pass if a path is given" do diff --git a/spec/unit/provider/exec/windows_spec.rb b/spec/unit/provider/exec/windows_spec.rb index 9b7168dfe6e..9ae14779853 100644 --- a/spec/unit/provider/exec/windows_spec.rb +++ b/spec/unit/provider/exec/windows_spec.rb @@ -88,8 +88,8 @@ end describe "#validatecmd" do - it "should fail if the command isn't absolute and there is no path" do - expect { provider.validatecmd('foo') }.to raise_error(Puppet::Error, /'foo' is not qualified and no path was specified/) + it "should not fail if the command isn't absolute and there is no path" do + expect(provider.validatecmd('foo')).to eq(nil) end it "should not fail if the command is absolute and there is no path" do diff --git a/spec/unit/provider/exec_spec.rb b/spec/unit/provider/exec_spec.rb index 3c9a676f6bf..8e3ada32985 100644 --- a/spec/unit/provider/exec_spec.rb +++ b/spec/unit/provider/exec_spec.rb @@ -73,20 +73,6 @@ def echo_from_ruby_exit_1(message) end context "when validating the command" do - it "redacts the arguments if the command is relative" do - expect { - apply_compiled_manifest(<<-MANIFEST) - exec { 'echo': - command => Sensitive.new('echo #{supersecret}') - } - MANIFEST - }.to raise_error do |err| - expect(err).to be_a(Puppet::Error) - expect(err.message).to match(/'echo' is not qualified and no path was specified. Please qualify the command or specify a path./) - expect(err.message).to_not match(/#{supersecret}/) - end - end - it "redacts the arguments if the command is a directory" do dir = tmpdir('exec') apply_compiled_manifest(<<-MANIFEST) diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb index ebc6f48038a..06491b203f4 100644 --- a/spec/unit/type/exec_spec.rb +++ b/spec/unit/type/exec_spec.rb @@ -910,11 +910,6 @@ def instance(path) let :abs do make_absolute('/bin/echo') end let :path do make_absolute('/bin') end - it "should fail with relative command and no path" do - expect { type.new(:command => rel) }. - to raise_error Puppet::Error, /no path was specified/ - end - it "should accept a relative command with a path" do expect(type.new(:command => rel, :path => path)).to be end