Git Product home page Git Product logo

puppet-sysctl's Introduction

Build Status

This is a puppet module to edit Linux kernel params using sysctl under the running kernel using a native type/provider. It modifies both the running kernel, and optionally will persist settings in /etc/sysctl.conf

EXAMPLE USAGE:

# puppet resource sysctl net.ipv4.ip_local_port_range permanent=no value="32768"$'\t'"61000"
notice: /Sysctl[net.ipv4.ip_local_port_range]/value: value changed '32768 61001' to '32768 61000'
sysctl { 'net.ipv4.ip_local_port_range':
  ensure    => 'present',
  permanent => 'yes',
  value     => '32768 61000',
}

There are some things to be aware of - namely:

First - by default the available params are available on your platform by running sysctl -a

Running puppet resource will give you available kernel tunables in the Puppet DSL

By default, we use /etc/sysctl.conf - to alter the target file) use path => '/etc/adifferentsysctl.conf'

To change sysctl.conf use

permanent => yes|no

You can stick pretty much any string in value, note for multiwords use a single space - the provider squashes multiple spaces between single values to a single space.

License:

See LICENSE file

Changelog:

  • 9th July 2014 - adding Travis CI
  • 16th Sept 2015 - update README

puppet-sysctl's People

Contributors

fiddyspence avatar petems avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

puppet-sysctl's Issues

What is failonfail in this line ?

  Puppet::Provider::Command.new(@name, @path, Puppet::Util, Puppet::Util::Execution, { :failonfail => true, :combine => true, :custom_environment => @custom_environment })

uninitialized constant Puppet::Provider::CommandDefiner

Hi all, I've installed this module (really useful indeed!) but I'm unable to make it work on machines with puppet agent < 3.X
On machines with 2.7 or 2.6 (I have some legacy issues here :) )I got this error:

err: Could not retrieve catalog from remote server: Could not intern from pson: Could not autoload sysctl: Could not autoload /var/lib/puppet/lib/puppet/provider/sysctl/linux3.rb: uninitialized constant Puppet::Provider::CommandDefiner

Basically it seems that linux3.rb gets loaded even on 2.X agents (the server is 3.4 in either cases)

I searched but found no indication of versions supported by this module; moreover I found this scary warning, trying to look at the code:

"This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future."

so I stopped digging and opened an issue :)

We should strip tabs from sysctl output

Easier to paste sysctl params as space delimited, and remove spaces from the strings that are output from sysctl for comparison (since sysctl will do spaces to tabs for us properly, etc).

Conflicts with hercules-team/augeasproviders

Warning: Found multiple default providers for sysctl: augeas, linux; using augeas
Error: /Stage[main]/System_config/Sysctl[net.ipv4.conf.default.accept_source_route]: Could not evaluate: Invalid parameter target(:target)
...and many more

Persistent entries in /etc/sysctl.conf multiplicate

Puppet: 2.8.3
OS: Oracle Linux 6.4
Module version: 0.3.3

When running sysctl with permanent => "yes" entries in /etc/sysctl.conf are written every time, leading to multiple entries that are identical.
I suspect problem when comparing permanent attribute (strings) using == operator.
I have modified module as follows:

diff -ru sysctl/lib/puppet/provider/sysctl/linux.rb sysctl.n/lib/puppet/provider/sysctl/linux.rb
--- sysctl/lib/puppet/provider/sysctl/linux.rb  2014-01-23 21:02:44.000000000 +0100
+++ sysctl.n/lib/puppet/provider/sysctl/linux.rb    2014-01-27 10:26:15.657000282 +0100
@@ -28,9 +28,9 @@
         confval = sysctlconf.grep(/^#{setting_name}\s?=/)
         if confval.empty?
           value = setting_value
-          permanent = 'no'
+          permanent = :false
         else
-          permanent = 'yes'
+          permanent = :true
           unless confval[0].split(/=/)[1].gsub(/\s+/,' ').strip == setting_value
             value = "outofsync(sysctl:#{setting_value},config:#{confval[0].split(/=/)[1].strip})"
           else
@@ -64,7 +64,7 @@
   end

   def permanent=(ispermanent)
-    if ispermanent == "yes"
+    if ispermanent == :true
       b = ( @resource[:value] == nil ? value : @resource[:value] )
       File.open(@resource[:path], 'a') do |fh|
         fh.puts "#{@resource[:name]} = #{b}"
diff -ru sysctl/lib/puppet/type/sysctl.rb sysctl.n/lib/puppet/type/sysctl.rb
--- sysctl/lib/puppet/type/sysctl.rb    2014-01-23 21:02:44.000000000 +0100
+++ sysctl.n/lib/puppet/type/sysctl.rb  2014-01-27 10:26:15.656000284 +0100
@@ -18,9 +18,12 @@
     end
   end

-  newproperty(:permanent) do
+  newproperty(:permanent, :boolean => true) do
     desc "whether the value should be in [/etc/sysctl.conf]"
-    newvalues (/yes|no/)
+    newvalues(:true, :false)
+    aliasvalue("yes", :true)
+    aliasvalue("no", :false)
+    defaultto(:false)
   end

   newparam(:path) do

Glitch when adding new parameters if sysctl.conf file doesn't have a newline at the end

If for some reason the initial /etc/sysctl.conf file on the server doesn't have a newline at the end of the file, using the sysctl type to add a new parameter doesn't work properly. The new parameter entry gets appended to the last line of the file instead of appended on a new line.

For example, when starting with this initial file (no newline after the 1):

# /etc/sysctl.conf
kernel.randomize_va_space = 1

... declaring the following resource and running Puppet once ...

sysctl { 'fs.file-max':
  ensure    => 'present',
  permanent => 'yes',
  value     => '6815744',
}

... results in the following file:

# /etc/sysctl.conf
kernel.randomize_va_space = 1fs.file-max = 6815744

... on the subsequent Puppet run the resource will update the file again:

# /etc/sysctl.conf
kernel.randomize_va_space = 1fs.file-max = 6815744
fs.file-max = 6815744

Multiple entry behavior

First off, you should not have multiple values so feel free to just close this issue on this fact.

If I have two values eg.
m.swappiness = 70
m.swappiness = 70

and I change my puppet code:
sysctl { 'vm.swappiness':
ensure => 'present',
permanent => 'true',
value => '80',
}

Both values will be changed, which is expected.

If I however change the second entry value, back to 70 and I run puppet agent -t the change will not be picked up because the first line is correct and no further parsing occurs.

Struggling to configure this for different profiles

Has anyone tried to use this module with different kernel settings for different applications. I use profiles to separate different app nodes and like to configure .pp file specific to that node.
Please help !

Invalid sysctl parameter

I recently upgraded from 0.0.1 to 0.3.5 and have run into an error with a particular parameter that was valid before, but now is not. kernel.shmall does not work but kernel.shmmax does:

justin@db2 ~ $ sysctl kernel.shmall                                                                  
kernel.shmall = 4194304
justin@db2 ~ $ sudo puppet resource --debug sysctl kernel.shmall value="4194304"                     
Debug: Loaded state in 0.05 seconds
Debug: Prefetching linux resources for sysctl
Debug: Executing '/sbin/sysctl -a'
Debug: Executing '/sbin/sysctl -a'
Debug: 
Error: Invalid sysctl parameter
Error: /Sysctl[kernel.shmall]/ensure: change from absent to present failed: Invalid sysctl parameter
Debug: Finishing transaction 70133283162760
Debug: Storing state
Debug: Stored state in 0.14 seconds
sysctl { 'kernel.shmall':
  ensure => 'absent',
}
justin@db2 ~ $ sysctl kernel.shmmax                                                                  
kernel.shmmax = 4294967296
justin@db2 ~ $ sudo puppet resource --debug sysctl kernel.shmmax value="4294967296"                  
Debug: Loaded state in 0.05 seconds
Debug: Prefetching linux resources for sysctl
Debug: Executing '/sbin/sysctl -a'
Debug: Finishing transaction 69975748475600
Debug: Storing state
Debug: Stored state in 0.15 seconds
sysctl { 'kernel.shmmax':
  ensure => 'present',
  value  => '4294967296',
}

Ubuntu 12.04
Pupppet 3.6.2

Related: a9d9d04

irb(main):002:0> sysctloutput = `sysctl -a`.split(/\r?\n/)
irb(main):003:0> sysctloutput.grep(/^kernel.shmmax\s?=/)
=> ["kernel.shmmax = 4294967296"]
irb(main):004:0> sysctloutput.grep(/^kernel.shmall\s?=/)
=> ["kernel.shmall = 4194304"]

Setting path for alternate config loops when permanent option is set to yes

In the below example, the file /etc/sysctl.d/90-oracle.conf gets the kernel.shmmax settings added during every run.

Sysctl {
path => '/etc/sysctl.d/90-oracle.conf',
}

sysctl { 'kernel.shmmax':
ensure => 'present',
permanent => 'yes',
value => 779538432,
}

Result in /etc/sysctl.d/90-oracle.conf
kernel.shmmax = 779538432
kernel.shmmax = 779538432
kernel.shmmax = 779538432

Every puppet run lines are duplicated in sysctl file

I'm running puppet version 3.7.2 and the latest master commit from this repo (commit: 9ae286b)

The code from my manifest file is:

  Sysctl {
    path      => '/etc/sysctl.d/50-puppet_customer_router.conf',
    permanent => 'yes',
    ensure    => 'present',
  }

  sysctl { 'net.ipv4.ip_forward':
    value     => '1',
  }

The output of two runs are:

root@server01:/etc/sysctl.d# puppet agent -tv ; cat 50-puppet_customer_router.conf 
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for server01.example.local
Info: Applying configuration version '1417619512'
Notice: /Stage[main]/Profiles::Customer_router/Sysctl[net.ipv4.ip_forward]/permanent: permanent changed 'false' to 'true'
Notice: Finished catalog run in 4.06 seconds

net.ipv4.ip_forward = 1
root@server01:/etc/sysctl.d# puppet agent -tv ; cat 50-puppet_customer_router.conf 
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for server01.example.local
Info: Applying configuration version '1417619532'
Notice: /Stage[main]/Profiles::Customer_router/Sysctl[net.ipv4.ip_forward]/permanent: permanent changed 'false' to 'true'
Notice: Finished catalog run in 3.98 seconds

net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
root@server01:/etc/sysctl.d# 

The server I'm running this on is an ubuntu-14.04 server.
I've tried to debug your puppet module, but don't understand why it's going wrong at the moment.

error

While executing correctly and adding all new parameters, it throws errors:

undefined method `find' for nil:NilClass
/Stage[main]/Sysctltweak::Noipvsix/Sysctl[net.ipv6.conf.lo.disable_ipv6]/value  change from 0 to 1 failed: undefined method `find' for nil:NilClass

Code:

class sysctltweak::noipvsix {
    sysctl { 'net.ipv6.conf.all.disable_ipv6':
        ensure    => 'present',
        permanent => 'yes',
        value     => '1',
        path      => '/etc/sysctl.d/disable-ipv6.conf',
    }

    sysctl { 'net.ipv6.conf.default.disable_ipv6':
        ensure    => 'present',
        permanent => 'yes',
        value     => '1',
        path      => '/etc/sysctl.d/disable-ipv6.conf',
    }

    sysctl { 'net.ipv6.conf.lo.disable_ipv6':
        ensure    => 'present',
        permanent => 'yes',
        value     => '1',
        path      => '/etc/sysctl.d/disable-ipv6.conf',
    }
}

and after run in /etc/sysctl.d/disable-ipv6.conf i see:

net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.all.disable_ipv6 = 1

UPD: happens only on first run. On second:

2013-04-12T17:28:47.882851+04:00 frigate puppet-agent[46925]: Caught TERM; calling stop
2013-04-12T17:28:48.949318+04:00 frigate puppet-agent[49749]: Starting Puppet client version 3.1.1
2013-04-12T17:28:48.949794+04:00 frigate puppet-agent[49749]: Reopening log files
2013-04-12T17:29:08.214319+04:00 frigate puppet-agent[49756]: Finished catalog run in 6.14 seconds

Even if i remove files i can't reproduce it.

Setting ensure to absent is not idempotent

We have had tcp_mem set in our environment for a while now. We recently set the ensure on that value to absent. The module removed the value from /etc/sysctl.conf but it reports is as removed every run:

Notice: /Stage[main]/Profile::Sysctl/Sysctl[net.ipv4.tcp_mem]/ensure: removed

This is how it is currently set:

        'net.ipv4.tcp_mem':
          ensure    => 'absent',
          permanent => 'yes',
          value     => '50576 64768 98152';

Inconsistent behavior for certain sysctl keys.

Some of the sysctl keys do not behave consistently. For example:

Removes net.ipv4.ip_forward entry from /etc/sysctl.conf

sysctl { "net.ipv4.ip_forward":
ensure => absent,
permanent => yes,
}

Different key such as net.bridge.bridge-nf-call-iptables doesn't do the same

sysctl { "net.bridge.bridge-nf-call-iptables":
ensure => absent,
permanent => yes,
}

Inline Documentation

The README file at the top of this bundle does not show up in a "puppet doc" run

I run this command:

puppet doc --outputdir /htdocs/puppetmaster --mode rdoc --manifestdir <$confdir>/manifests --modulepath <$confdir>/modules

For this module, I get a file listing and a plugin listing, but in the lower half of the left hand column - where I expect to see class listings for the module - it says:

"Not Found
The requested URL /puppetmaster/modules/fr_sysctl.html was not found on this server."

Is there any way to get this README to show up ?

Deleting sysctl.conf entries; multiple entries

  1. Looking through the code, there is an ensure => absent option and there is a destroy function, but I can't seem to get them to work to remove entries in sysctl.conf. Is that functionality supported, or does it need to be written?

  2. If there are multiple entries for a sysctl setting, the module appears to update the first one only, which I believe is not the one that is actually read (iirc, later entries take precedence). Should there be an option either to combine duplicate entries and/or update the last entry (or I guess both entries)?

e.g.
kernel.shmmax 10000
kernel.shmmax 12000

I'm willing to work on a pull request if necessary, but I'd like to get input on direction before heading off into code land.

Warnings when listing resources

puppet: 2.8.3
sysctl module version: 0.3.3
OS: Linux (Oracle Linux 6.4)

puppet resource sysctl

warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl dev.cdrom.info found in both linux and linux; skipping the linux version
warning: Sysctl net.ipv4.route.gc_interval found in both linux and linux; skipping the linux version

Comment abbility

Disclaimer: Comments should not matter and does not belong in a config file.

However it would be useful still to have the ability to associate a comment with a sysctl setting and have that in a config file for those of use that are transitioning to a modern way of doing things.

0.3.3 tag doesn't exist, but does on puppet forge.

We're using forge module version 0.3.3 but want to switch to using git in our Puppetfile.

0.3.3 doesn't exist in this repo however. Could this be tagged?

Also - where is the changelog / release notes kept for version upgrades? It'd be nice to know what's new in 0.3.5.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.