sysctl cookbok is deprecated but still widely used. Chef core already has sysctl resource
Below is the short example how could we migrate from sysctl cookbook, without changing attributes structure.
# Code taken from https://github.com/Sous-Chefs-Boneyard/sysctl/blob/v0.6.2/libraries/sysctl.rb and a bit modified
def compile_attr(prefix, v)
case v
when Array
return {prefix => "#{v.join(' ')}"}
when String, Fixnum, Bignum, Float, Symbol
{prefix => "#{v}"}
when Hash, Chef::Node::Attribute
prefix += '.' unless prefix.empty?
return v.map { |key, value| compile_attr("#{prefix}#{key}", value) }.flatten
else
fail Chef::Exceptions::UnsupportedAction, "Sysctl can't handle values of type: #{v.class}"
end
end
params = {}
params['sysctl'] = {}
params['sysctl']['params'] = {}
params['sysctl']['params']['vm'] = {}
params['sysctl']['params']['vm']['max_map_count'] = 262_144
params['sysctl']['params']['vm']['swappiness'] = 1
compiled_params = compile_attr('',params)
compiled_params.each do |entry|
entry.each do |k, v|
sysctl "#{k}" do
value #{v}
end
end
end
code above is just an example, which could help in writing own common helper to apply systcl configuration from the same attributes branch.