Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final PR for docs, data types, cleanup and testing #42

Merged
merged 3 commits into from
Sep 15, 2018
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Change log

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).

## [v0.0.12](https://github.com/duritong/puppet-sysctl/tree/v0.0.12) (2018-07-24)

[Full Changelog](https://github.com/duritong/puppet-sysctl/compare/v0.0.11...v0.0.12)

### Changed

- Update testing, readme and metadata [\#39](https://github.com/duritong/puppet-sysctl/pull/39) ([tobias-urdin](https://github.com/tobias-urdin))

### Added

None.

### Fixed

None.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ gem 'puppet-lint'
gem 'metadata-json-lint'
gem 'puppetlabs_spec_helper'
gem 'rspec-puppet'
gem 'rspec-puppet-facts'
gem 'rake'
185 changes: 140 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,158 @@
Requirements
============
# sysctl

#### Table of Contents

1. [Description](#description)
1. [Setup - The basics of getting started with sysctl](#setup)
* [Beginning with sysctl](#beginning-with-sysctl)
1. [Usage - Configuration options and additional functionality](#usage)
* [Basic usage](#basic-usage)
* [Multiple tab-separated values](#multiple-tab-separated-values)
* [Custom target file](#custom-target-file)
* [Setting multiple sysctl keys](#setting-multiple-sysctl-keys)
* [Using hiera](#using-hiera)
1. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
1. [Limitations - OS compatibility, etc.](#limitations)
* [Puppet 3 support](#puppet-3-support)
1. [License](#license)
1. [Authors](#authors)

## Description

[![Build Status](https://travis-ci.org/duritong/puppet-sysctl.png?branch=master)](https://travis-ci.org/duritong/puppet-sysctl)

Overview
--------
This module manages the sysctl configuration (in /etc/sysctl.conf by default) and runtime
values.

This modules allows to configure sysctl.
## Setup

Usage
-----
### Beginning with sysctl

node "mynode" inherits ... {
sysctl::value { "vm.nr_hugepages": value => "1583"}
}
To set a sysctl value in the configuration file and the runtime value. By default
sets the configuration in /etc/sysctl.conf by can be customized with the `target` parameter.

When setting a key that contains multiple values, use a tab to separate the
values:
```puppet
sysctl::value { 'vm.nr_hugepages':
value => '1583'
}```

node "mynode" inherits ... {
sysctl::value { 'net.ipv4.tcp_rmem':
value => "4096\t131072\t131072",
}
}
## Usage

If another config file then /etc/sysctl.conf (default) is required, use target for this:
### Basic usage

node "mynode" inherits ... {
sysctl::value { 'net.ipv4.tcp_rmem':
value => "4096\t131072\t131072",
target => '/etc/sysctl.d/mysysctl.conf',
}
}
The basic usage by setting the configuration file and runtime value.

To avoid duplication the sysctl::value calls multiple settings can be
managed like this:
```puppet
sysctl::value { 'vm.nr_hugepages':
value => '1583'
}```

$my_sysctl_settings = {
"net.ipv4.ip_forward" => { value => 1 },
"net.ipv6.conf.all.forwarding" => { value => 1 },
}

# Specify defaults for all the sysctl::value to be created (
$my_sysctl_defaults = {
require => Package['aa']
}

create_resources(sysctl::value,$my_sysctl_settings,$my_sysctl_defaults)
### Multiple tab-separated values

Puppet 3 support
----------------
When setting a key that contains multiple values, use a tab to separate the values.

The 0.0.12 release will be the last version that supports Puppet 3 support.
```puppet
sysctl::value { 'net.ipv4.tcp_rmem':
value => "4096\t131072\t131072",
}```

License
-------
### Custom target file

Copyright (C) 2011 Immerda Project Group
If another config file then the default /etc/sysctl.conf is required.

```puppet
sysctl::value { 'vm.nr_hugepages':
value => '1583',
target => '/etc/sysctl.d/mysysctl.conf',
}```

### Setting multiple sysctl keys

To avoid duplication the sysctl::value calls multiple settings can be managed with
the `sysctl::values` resource.

```puppet
$my_sysctl_settings = {
'net.ipv4.ip_forward' => { value => 1 },
'net.ipv6.conf.all.forwarding' => { value => 1 },
}

# Specify defaults for all the sysctl::value to be created
$my_sysctl_defaults = {
require => Package['aa']
}

create_resources(sysctl::value, $my_sysctl_settings, $my_sysctl_defaults)

# or by using the sysctl::values resource
sysctl::values { 'multiple':
args => $my_sysctl_settings,
defaults => $my_sysctl_defaults,
}
```

### Using hiera

You can configure hiera data and pass it to the `sysctl::values` resource.

Author mh <mh@immerda.ch>, Modified by Nicolas Zin <nicolas.zin@savoirfairelinux.com>, Modified by Artem Sidorenko <artem@2realities.com>
```
sysctl::values:
net.ipv4.ip_forward:
value: 1
net.ipv6.conf.all.forwarding:
value: 1
```

## Reference

Here, include a complete list of your module's classes, types, providers,
facts, along with the parameters for each. Users refer to this section (thus
the name "Reference") to find specific details; most users don't read it per
se.

## Limitations

For an extensive list of supported operating systems, see [metadata.json](https://github.com/duritong/puppet-sysctl/blob/master/metadata.json)

### Puppet 3 support

The 0.0.12 release is the last version that supports Puppet 3.

## License

Copyright (C) 2011 Immerda Project Group

Licence: GPL v2
sysctl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

sysctl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with sysctl. If not, see <http://www.gnu.org/licenses/>.

## Authors

This module is based on work by mh (mh@immerda.ch).
The following contributors have contributed to this module, in alphabetical order.

* Artem Sidorenko (artem-sidorenko)
* Beefsalad (beefsalad)
* Decibelhertz (decibelhertz)
* Dominic (dol)
* Duncan Ward (ddub)
* Duritong (duritong)
* Emilien Macchi (EmilienM)
* Jason Hancock (jasonhancock)
* Merritt Krakowitzer (mkrakowitzer)
* Mh (mh@immerda.ch)
* Nicolas Zin (nicolas.zin@savoirfairelinux.com)
* Patrick Debois (jedi4ever)
* Sebastian Reitenbach (buzzdeee)
* Stefan Möding (smoeding)
* Thracky (Thracky)
* Tobias Urdin (tobias-urdin)
27 changes: 27 additions & 0 deletions examples/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
sysctl::value { 'net.ipv4.ip_forward':
value => 1,
}

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

sysctl::value { 'net.ipv4.tcp_rmem':
value => "4096\t131072\t131072",
}

sysctl::value { 'vm.nr_hugepages':
value => '1583',
target => '/etc/sysctl.d/mysysctl.conf',
}

$my_sysctl_settings = {
'net.ipv4.ip_forward' => { value => 1 },
'net.ipv6.conf.all.forwarding' => { value => 1 },
}

create_resources(sysctl::value, $my_sysctl_settings, {})

sysctl::values { 'multiple':
args => $my_sysctl_settings,
}
13 changes: 4 additions & 9 deletions lib/puppet/provider/sysctl/parsed.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
require 'puppet/provider/parsedfile'

sysctlconf = "/etc/sysctl.conf"
default_target = '/etc/sysctl.conf'

Puppet::Type.type(:sysctl).provide(:parsed,
:parent => Puppet::Provider::ParsedFile,
:default_target => sysctlconf,
:filetype => :flat
) do

confine :exists => sysctlconf
Puppet::Type.type(:sysctl).provide(:parsed, :parent => Puppet::Provider::ParsedFile,
:default_target => default_target, :filetype => :flat) do
confine :exists => default_target
text_line :comment, :match => /^\s*#/;
text_line :blank, :match => /^\s*$/;

record_line :parsed, :fields => %w{name val}, :joiner => '=', :separator => /\s*=\s*/

end
7 changes: 2 additions & 5 deletions lib/puppet/provider/sysctl_runtime/sysctl_runtime.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Puppet::Type.type(:sysctl_runtime).provide(:sysctl_runtime,
:parent => Puppet::Provider
) do
desc "This provider changes the runtime values of kernel parameters"
Puppet::Type.type(:sysctl_runtime).provide(:sysctl_runtime, :parent => Puppet::Provider) do
desc 'This provider changes the runtime values of kernel parameters'

commands :sysctl => 'sysctl'

Expand Down Expand Up @@ -45,5 +43,4 @@ def self.prefetch(resources)
def val=(value)
sysctl("#{resource[:name]}=#{value}")
end

end
49 changes: 27 additions & 22 deletions lib/puppet/type/sysctl.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
Puppet::Type.newtype(:sysctl) do
@doc = <<-EOF
@summary
Manages kernel parameters in /etc/sysctl.conf. This will only
edit the configuration file, and not change any of the runtime
values. If you wish changes to be activated right away, use the
sysctl::value definition or the sysctl_runtime resource type.

@doc = "Manages kernel parameters in /etc/sysctl.conf. This will
only edit the configuration file, and not change any of the runtime
values. If you wish changes to be activated right away, use the
sysctl::value definition or the sysctl_runtime resource type."
@api public
EOF

ensurable
ensurable

newparam(:name, :namevar => true) do
desc "Name of the parameter"
isnamevar
end
newparam(:name, :namevar => true) do
desc 'Name of the parameter'
isnamevar
end

newproperty(:val) do
desc "Value the parameter should be set to"
end
newproperty(:val) do
desc 'Value the parameter should be set to'
end

newproperty(:target) do
desc "Name of the file to store parameters in"
defaultto { if @resource.class.defaultprovider and
@resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
@resource.class.defaultprovider.default_target
else
nil
end
}
end
newproperty(:target) do
desc 'Name of the file to store parameters in'
defaultto {
if (@resource.class.defaultprovider and
@resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile))
@resource.class.defaultprovider.default_target
else
nil
end
}
end
end
22 changes: 13 additions & 9 deletions lib/puppet/type/sysctl_runtime.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
Puppet::Type.newtype(:sysctl_runtime) do
@doc = <<-EOF
@summary
Manages kernel runtime parameters.
This type doesn't change any configuration files.

@doc = "Manages kernel runtime parameters. This type doesn't change any configuration files."
@api public
EOF

newparam(:name, :namevar => true) do
desc "Name of the parameter"
isnamevar
end
newparam(:name, :namevar => true) do
desc 'Name of the parameter'
isnamevar
end

newproperty(:val) do
desc "Value the parameter should be set to"
end

newproperty(:val) do
desc 'Value the parameter should be set to'
end
end
13 changes: 12 additions & 1 deletion manifests/base.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# common things for sysctl
# @summary
# The base class that manages the creation of
# the default sysctl configuration file.
#
# @api private
class sysctl::base {

# we dont have puppetlabs-stdlib so we cannot use
# assert_private() function here.
if $module_name != $caller_module_name {
fail('sysctl::base is a private class')
}

file { '/etc/sysctl.conf':
ensure => 'present',
owner => 'root',
Expand Down
Loading