Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/puppet/provider/sysctl/augeas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def create
commented = aug.match("$target/#comment[.=~regexp('#{resource[:name]}([^a-z.].*)?')]")
aug.insert(commented.first, resource[:name], false) unless commented.empty?
aug.set(resource_path, value)
self.class.set_managed_comment(aug, resource[:name], resource[:comment]) if resource[:comment]
setvars(aug)
end
end
Expand Down Expand Up @@ -272,6 +273,9 @@ def cleanup_duplicates
end

def valid_resource?(name)
# The key only needs to exist on the live system when applying it
return true if resource && resource[:apply] == :false

@property_hash.is_a?(Hash) && @property_hash[:name] == name
end

Expand Down
42 changes: 42 additions & 0 deletions spec/unit/puppet/provider/sysctl/augeas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,48 @@
end
end

context 'when persisting a key missing from the live system' do
let(:tmptarget) { aug_fixture('empty') }
let(:target) { tmptarget.path }

before do
expect(provider_class).to receive(:sysctl).with(['-e', 'net.future.key']).twice.and_return('')
expect(provider_class).not_to receive(:sysctl).with('-n', 'net.future.key')
expect(provider_class).not_to receive(:sysctl).with('-w', 'net.future.key=1')
end

it 'creates the entry without applying it' do
apply!(Puppet::Type.type(:sysctl).new(
name: 'net.future.key',
ensure: 'present',
value: '1',
comment: 'test',
apply: false,
target: target,
provider: 'augeas'
))

augparse(target, 'Sysctl.lns', '
{ "#comment" = "net.future.key: test" }
{ "net.future.key" = "1" }
')
end

it 'creates the entry without ensure' do
apply!(Puppet::Type.type(:sysctl).new(
name: 'net.future.key',
value: '1',
apply: false,
target: target,
provider: 'augeas'
))

augparse(target, 'Sysctl.lns', '
{ "net.future.key" = "1" }
')
end
end

context 'with full file' do
let(:tmptarget) { aug_fixture('full') }
let(:target) { tmptarget.path }
Expand Down
Loading