forked from voxpupuli/puppet-augeasproviders
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsysctl.rb
73 lines (61 loc) · 2.16 KB
/
sysctl.rb
1
2
3
4
5
6
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
67
68
69
70
71
72
73
# Manages entries in /etc/sysctl.conf
#
# Copyright (c) 2012 Dominic Cleal
# Licensed under the Apache License, Version 2.0
Puppet::Type.newtype(:sysctl) do
@doc = "Manages entries in /etc/sysctl.conf."
ensurable
newparam(:name) do
desc "The name of the setting, e.g. net.ipv4.ip_forward"
isnamevar
end
module SysctlValueSync
def insync?(is)
if resource[:apply] == :true
@live_value = provider.live_value
equal(should, is) and equal(should, @live_value)
else
equal(should, is)
end
end
def change_to_s(current, new)
if resource[:apply] == :true
if equal(current, new)
return "changed live value from '#{@live_value}' to '#{new}'"
elsif equal(@live_value, new)
return "changed configuration value from '#{current}' to '#{new}'"
else
return "changed configuration value from '#{current}' to '#{new}' and live value from '#{@live_value}' to '#{new}'"
end
else
return "changed configuration value from '#{current}' to '#{new}'"
end
end
def equal(a, b)
a.gsub(/\s+/, ' ') == b.gsub(/\s+/, ' ')
end
end
newproperty(:val) do
desc "An alias for 'value'. Maintains interface compatibility with the traditional ParsedFile sysctl provider. If both are set, 'value' will take precedence over 'val'."
include SysctlValueSync
end
newproperty(:value) do
desc "Value to change the setting to. Settings with multiple values (such as net.ipv4.tcp_mem) are represented as a single whitespace separated string."
include SysctlValueSync
end
newparam(:target) do
desc "The file in which to store the settings, defaults to
`/etc/sysctl.conf`."
end
newproperty(:comment) do
desc "Text to be stored in a comment immediately above the entry. It will be automatically prepended with the name of the setting in order for the provider to know whether it controls the comment or not."
end
newparam(:apply, :boolean => true) do
desc "Whether to apply the value using the sysctl command."
newvalues(:true, :false)
defaultto(true)
end
autorequire(:file) do
self[:target]
end
end