Update directory structure & allow to configure paths (tmp, log, cache)

This commit is contained in:
Nicolas Le Goff
2014-09-05 11:28:25 +02:00
parent 69fd50906f
commit de7988689e
2201 changed files with 850 additions and 13650 deletions

View File

@@ -0,0 +1,29 @@
2014-01-20 - 0.3.0
* Add optional comment inside the sysctl.d file.
* Use sysctl -p with the created/modified file instead of sysctl -w (#3).
* Fix purge and set its default to false (#7, tehmaspc).
2013-10-02 - 0.2.0
* Add optional prefix to the sysctl.d file name, to force ordering.
2013-06-25 - 0.1.1
* Make purge optional, still enabled by default.
* Add rspec tests (Justin Lambert).
* Minor fix for values with spaces (needs more changes to be robust).
2013-03-06 - 0.1.0
* Update README to markdown.
* Change to recommended 2 space indent.
2012-12-18 - 0.0.3
* Add feature to update existing values in /etc/sysctl.conf.
* Apply setting on each run if needed (hakamadare).
* Make sure $ensure => absent still works with the above change.
2012-09-19 - 0.0.2
* Fix deprecation warnings.
* Fix README markup.
2012-07-19 - 0.0.1
* Initial module release.

View File

@@ -0,0 +1,8 @@
source :rubygems
puppetversion = ENV['PUPPET_VERSION']
gem 'puppet', puppetversion, :require => false
gem 'puppet-lint'
gem 'rspec-puppet'
gem 'puppetlabs_spec_helper', '>= 0.4.0'

View File

@@ -0,0 +1,14 @@
Copyright (C) 2011-2013 Matthias Saou
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,8 @@
name 'thias-sysctl'
version '0.3.0'
source 'git://github.com/thias/puppet-sysctl'
author 'Matthias Saou'
license 'Apache 2.0'
summary 'Sysctl module'
description "Manage sysctl variable values."
project_page 'https://github.com/thias/puppet-sysctl'

View File

@@ -0,0 +1,58 @@
# puppet-sysctl
## Overview
Manage sysctl variable values. All changes are immediately applied, as well as
configured to become persistent. Tested on Red Hat Enterprise Linux 6.
* `sysctl` : Definition to manage sysctl variables by setting a value.
* `sysctl::base`: Base class (included from the definition).
For persistence to work, your Operating System needs to support looking for
sysctl configuration inside `/etc/sysctl.d/`.
You may optionally enable purging of the `/etc/sysctl.d/` directory, so that
all files which are not (or no longer) managed by this module will be removed.
Beware that for the purge to work, you need to either have at least one
sysctl definition call left for the node, or include `sysctl::base` manually.
You may also force a value to `ensure => absent`, which will always work.
For the few original settings in the main `/etc/sysct.conf` file, the value is
also replaced so that running `sysctl -p` doesn't revert any change made by
puppet.
## Examples
Enable IP forwarding globally :
```puppet
sysctl { 'net.ipv4.ip_forward': value => '1' }
```
Set a value for maximum number of connections per UNIX socket :
```puppet
sysctl { 'net.core.somaxconn': value => '65536' }
```
Make sure we don't have any explicit value set for swappiness, typically
because it was set at some point but no longer needs to be. The original
value for existing nodes won't be reset until the next reboot :
```puppet
sysctl { 'vm.swappiness': ensure => absent }
```
If the order in which the files get applied is important, you can set it by
using a file name prefix, which could also be set globally from `site.pp` :
```puppet
Sysctl { prefix => '60' }
```
To enable purging of settings, you can use hiera to set the `sysctl::base`
`$purge` parameter :
```yaml
---
# sysctl
sysctl::base::purge: true
```

View File

@@ -0,0 +1,7 @@
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint'
PuppetLint.configuration.send("disable_80chars")
PuppetLint.configuration.send("disable_autoloader_layout")
PuppetLint.configuration.send("disable_quoted_booleans")

View File

@@ -0,0 +1,26 @@
# Class: sysctl::base
#
# Common part for the sysctl definition. Not meant to be used on its own.
#
class sysctl::base (
$purge = false,
) {
if $purge {
$recurse = true
} else {
$recurse = false
}
file { '/etc/sysctl.d':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
# Magic hidden here
purge => $purge,
recurse => $recurse,
}
}

View File

@@ -0,0 +1,66 @@
# Define: sysctl
#
# Manage sysctl variable values.
#
# Parameters:
# $value:
# The value for the sysctl parameter. Mandatory, unless $ensure is 'absent'.
# $prefix:
# Optional prefix for the sysctl.d file to be created. Default: none.
# $ensure:
# Whether the variable's value should be 'present' or 'absent'.
# Defaults to 'present'.
#
# Sample Usage :
# sysctl { 'net.ipv6.bindv6only': value => '1' }
#
define sysctl (
$value = undef,
$prefix = undef,
$comment = undef,
$ensure = undef,
) {
include sysctl::base
# If we have a prefix, then add the dash to it
if $prefix {
$sysctl_d_file = "${prefix}-${title}.conf"
} else {
$sysctl_d_file = "${title}.conf"
}
# The permanent change
file { "/etc/sysctl.d/${sysctl_d_file}":
ensure => $ensure,
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/sysctl.d-file.erb"),
notify => [
Exec["sysctl-${title}"],
Exec["update-sysctl.conf-${title}"],
],
}
if $ensure != 'absent' {
# The immediate change + re-check on each run "just in case"
exec { "sysctl-${title}":
command => "/sbin/sysctl -p /etc/sysctl.d/${sysctl_d_file}",
refreshonly => true,
require => File["/etc/sysctl.d/${sysctl_d_file}"],
}
# For the few original values from the main file
exec { "update-sysctl.conf-${title}":
command => "sed -i -e 's/^${title} *=.*/${title} = ${value}/' /etc/sysctl.conf",
path => [ '/usr/sbin', '/sbin', '/usr/bin', '/bin' ],
refreshonly => true,
onlyif => "grep -E '^${title} *=' /etc/sysctl.conf",
}
}
}

View File

@@ -0,0 +1,32 @@
{
"project_page": "https://github.com/thias/puppet-sysctl",
"version": "0.3.0",
"license": "Apache 2.0",
"description": "Manage sysctl variable values.",
"dependencies": [
],
"types": [
],
"name": "thias-sysctl",
"author": "Matthias Saou",
"summary": "Sysctl module",
"source": "git://github.com/thias/puppet-sysctl",
"checksums": {
"tests/init.pp": "e70e5327b9840b44699bb7fae71d47cd",
"spec/spec_helper.rb": "3ea886dd135e120afa31e0aab12e85b0",
"ChangeLog": "ed8052eb5cb46b92eaa03b882c11779e",
"LICENSE": "99219472697a01561e7630d63aaecdc1",
"Modulefile": "3b8a6a0dfff841a31118a5f46fde59da",
"spec/defines/sysctl_init_spec.rb": "21d524df70961750cb22f6b83349093e",
"manifests/init.pp": "0f7dd893b08ebbbec8994d14eca6701b",
"README.md": "ed4837849a1c4790b7178cd99824a204",
"spec/classes/sysctl_base_spec.rb": "6241cf3e290871c00b1bb3bbd5490108",
"templates/sysctl.d-file.erb": "0212783df32c499b3e9e343993f608da",
"manifests/base.pp": "9508015ce74b5ce1420ad8c8ebc7d3af",
"tests/base.pp": "1ba89838432dbc94339097327c19ae3d",
"Gemfile": "3ad486d60d90bfe4395b368b95481e01",
"Rakefile": "ab253b919e7093c2a5eb7adf0e39ffbc"
}
}

View File

@@ -0,0 +1,9 @@
require 'spec_helper'
describe 'sysctl::base', :type => :class do
it { should create_class('sysctl::base') }
it { should contain_file('/etc/sysctl.d') }
end

View File

@@ -0,0 +1,25 @@
require 'spec_helper'
describe 'sysctl', :type => :define do
let(:title) { 'net.ipv4.ip_forward'}
context 'present' do
let(:params) { { :value => '1' } }
it { should contain_file('/etc/sysctl.d/net.ipv4.ip_forward.conf').with(
:content => "net.ipv4.ip_forward = 1\n",
:ensure => nil
) }
it { should contain_exec('sysctl-net.ipv4.ip_forward') }
it { should contain_exec('update-sysctl.conf-net.ipv4.ip_forward')}
end
context 'absent' do
let(:params) { { :ensure => 'absent' } }
it { should contain_file('/etc/sysctl.d/net.ipv4.ip_forward.conf').with_ensure('absent') }
end
end

View File

@@ -0,0 +1,2 @@
require 'rubygems'
require 'puppetlabs_spec_helper/module_spec_helper'

View File

@@ -0,0 +1,6 @@
<% if @comment -%>
<% @comment.each do |line| -%>
# <%= line %>
<% end -%>
<% end -%>
<%= @title %> = <%= @value %>

View File

@@ -0,0 +1 @@
include sysctl::base

View File

@@ -0,0 +1,3 @@
sysctl { 'net.ipv4.ip_forward': value => '1' }
sysctl { 'net.core.somaxconn': value => '65536' }
sysctl { 'vm.swappiness': ensure => absent }