Puppet's boolean parameter type is only available in Puppet 3.3 and
higher, so change file_type's new "replace" parameter to a regular
parameter with true and false as possible values. This matches the
existing "multiple" parameter.
Puppet::Type.type(:file_line).provide(:ruby) do
def exists?
- if !resource[:replace] and count_matches(match_regex) > 0
+ if resource[:replace].to_s != 'true' and count_matches(match_regex) > 0
true
else
lines.find do |line|
end
def create
- unless !resource[:replace] and count_matches(match_regex) > 0
+ unless resource[:replace].to_s != 'true' and count_matches(match_regex) > 0
if resource[:match]
handle_create_with_match
elsif resource[:after]
-require 'puppet/parameter/boolean'
Puppet::Type.newtype(:file_line) do
desc <<-EOT
end
end
- newparam(:replace, :boolean => true, :parent => Puppet::Parameter::Boolean) do
+ newparam(:replace) do
desc 'If true, replace line that matches. If false, do not write line if a match is found'
+ newvalues(true, false)
defaultto true
end
:replace => 'asgadga',
}
)
- }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false, yes, no\./)
+ }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false\./)
end
end
context "when matching" do
expect(file_line[:ensure]).to eq :present
end
it 'should default to replace => true' do
- expect(file_line[:replace]).to eq true
+ expect(file_line[:replace]).to eq :true
end
it "should autorequire the file it manages" do