Skip to content
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
3 changes: 0 additions & 3 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ fixtures:
repositories:
stdlib:
repo: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
symlinks:
sysctl: "#{source_dir}"

34 changes: 0 additions & 34 deletions .github/workflows/run-pdk-tests-on-puppet-7.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/run-pdk-tests-on-puppet-8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Run pdk validate
uses: puppets-epic-show-theatre/action-pdk-validate@v1
Expand All @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Run unit tests
uses: puppets-epic-show-theatre/action-pdk-test-unit@v1
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
/spec/fixtures/modules/*
/tmp/
/vendor/
/.vendor/
/convert_report.txt
/update_report.txt
.DS_Store
.project
.envrc
/inventory.yaml
/spec/fixtures/litmus_inventory.yaml
.resource_types
.modules
.task_cache.json
.plan_cache.json
.rerun.json
bolt-debug.log
8 changes: 8 additions & 0 deletions .pdkignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@
/spec/fixtures/modules/*
/tmp/
/vendor/
/.vendor/
/convert_report.txt
/update_report.txt
.DS_Store
.project
.envrc
/inventory.yaml
/spec/fixtures/litmus_inventory.yaml
.resource_types
.modules
.task_cache.json
.plan_cache.json
.rerun.json
bolt-debug.log
/.fixtures.yml
/Gemfile
/.gitattributes
/.github/
/.gitignore
/.pdkignore
/.puppet-lint.rc
Expand Down
8 changes: 8 additions & 0 deletions .puppet-lint.rc
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
--fail-on-warnings
--relative
--no-80chars-check
--no-140chars-check
--no-class_inherits_from_params_class-check
--no-autoloader_layout-check
--no-documentation-check
--no-single_quote_string_with_variables-check
--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require:
- rubocop-performance
- rubocop-rspec
AllCops:
NewCops: enable
DisplayCopNames: true
TargetRubyVersion: '2.6'
Include:
Expand Down Expand Up @@ -527,6 +528,8 @@ Lint/DuplicateBranch:
Enabled: false
Lint/DuplicateMagicComment:
Enabled: false
Lint/DuplicateMatchPattern:
Enabled: false
Lint/DuplicateRegexpCharacterClassElement:
Enabled: false
Lint/EmptyBlock:
Expand Down Expand Up @@ -643,6 +646,8 @@ Style/ComparableClamp:
Enabled: false
Style/ConcatArrayLiterals:
Enabled: false
Style/DataInheritance:
Enabled: false
Style/DirEmpty:
Enabled: false
Style/DocumentDynamicEvalDefinition:
Expand Down Expand Up @@ -711,6 +716,8 @@ Style/RedundantHeredocDelimiterQuotes:
Enabled: false
Style/RedundantInitialize:
Enabled: false
Style/RedundantLineContinuation:
Enabled: false
Style/RedundantSelfAssignmentBranch:
Enabled: false
Style/RedundantStringEscape:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"recommendations": [
"puppet.puppet-vscode",
"rebornix.Ruby"
"Shopify.ruby-lsp"
]
}
26 changes: 17 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,33 @@ group :development do
gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "deep_merge", '~> 1.2.2', require: false
gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false
gem "facterdb", '~> 1.18', require: false
gem "metadata-json-lint", '~> 3.0', require: false
gem "puppetlabs_spec_helper", '~> 6.0', require: false
gem "rspec-puppet-facts", '~> 2.0', require: false
gem "codecov", '~> 0.2', require: false
gem "facterdb", '~> 2.1', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "facterdb", '~> 3.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "metadata-json-lint", '~> 4.0', require: false
gem "json-schema", '< 5.1.1', require: false
gem "rspec-puppet-facts", '~> 4.0', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "rspec-puppet-facts", '~> 5.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "dependency_checker", '~> 1.0.0', require: false
gem "parallel_tests", '= 3.12.1', require: false
gem "pry", '~> 0.10', require: false
gem "simplecov-console", '~> 0.5', require: false
gem "simplecov-console", '~> 0.9', require: false
gem "puppet-debugger", '~> 1.0', require: false
gem "rubocop", '= 1.48.1', require: false
gem "rubocop", '~> 1.50.0', require: false
gem "rubocop-performance", '= 1.16.0', require: false
gem "rubocop-rspec", '= 2.19.0', require: false
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
end
group :development, :release_prep do
gem "puppet-strings", '~> 4.0', require: false
gem "puppetlabs_spec_helper", '~> 8.0', require: false
gem "puppet-blacksmith", '~> 7.0', require: false
end
group :system_tests do
gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw]
gem "serverspec", '~> 2.41', require: false
gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw]
gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "serverspec", '~> 2.41', require: false
end

puppet_version = ENV['PUPPET_GEM_VERSION']
Expand Down
141 changes: 99 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,93 @@
# puppet-sysctl

## Overview
#### Table of Contents

1. [Module Description - What the module does and why it is useful](#module-description)
1. [Setup - The basics of getting started with sysctl](#setup)
* [What sysctl affects](#what-sysctl-affects)
* [Setup requirements](#setup-requirements)
* [Beginning with sysctl](#beginning-with-sysctl)
1. [Usage - Configuration options and additional functionality](#usage)
1. [Reference - Parameter reference](#reference)
1. [Limitations - OS compatibility, etc.](#limitations)
1. [Development - Guide for contributing to the module](#development)

## Module description

Manage sysctl variable values. All changes are immediately applied, as well as
configured to become persistent. Tested on Red Hat Enterprise Linux 6 and 7.
configured to become persistent.

* `sysctl` : Definition to manage sysctl variables by setting a value.
* `sysctl::base`: Base class (included from the definition).
* `sysctl`: Defined type to manage sysctl variables by setting a value.
* `sysctl::base`: Base class (included from the defined type).

For persistence to work, your Operating System needs to support looking for
sysctl configuration inside `/etc/sysctl.d/`.
## Setup

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.
### What sysctl affects

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.
* One file per variable in `/etc/sysctl.d/`.
* The `/etc/sysctl.d/` directory itself, which can optionally be purged.
* The few original settings in `/etc/sysctl.conf`: the value is also replaced
there, so that running `sysctl -p` does not revert a change made by Puppet.

You may also force a value to `ensure => absent`, which will always work.
### Setup requirements

For the few original settings in the main `/etc/sysctl.conf` file, the value is
also replaced so that running `sysctl -p` doesn't revert any change made by
puppet.
This module requires `puppetlabs/stdlib` (see `metadata.json` for the
supported versions). For persistence to work, the operating system needs to
support looking for sysctl configuration inside `/etc/sysctl.d/`.

## Examples
### Beginning with sysctl

Declare a `sysctl` resource. The `sysctl::base` class is included
automatically.

Enable IP forwarding globally :
```puppet
sysctl { 'net.ipv4.ip_forward': value => '1' }
```

Set a value for maximum number of connections per UNIX socket :
## Usage

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 :
Make sure there is no 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 is not 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` :
If the order in which the files get applied is important, set it with a file
name prefix, which can 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 :
### Purging

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 are removed.
For the purge to work, the node needs at least one `sysctl` resource, or
`sysctl::base` must be included manually. Forcing a value to
`ensure => absent` always works.

```yaml
---
# sysctl
sysctl::base::purge: true
```

## Hiera

It is also possible to manage all sysctl keys using hiera, through the
`$values` parameter of the `sysctl::base` class. If sysctl values are spread
across different hiera locations, it's also possible to merge all of them
instead of having only the last one applied, by setting the
`$hiera_merge_values` parameter to true.
### Hiera

All sysctl keys can be managed from Hiera through the `values` parameter of
the `sysctl::base` class. If the values are spread across different Hiera
levels, set `hiera_merge_values` to `true` to merge all of them instead of
only using the first one found.

```yaml
sysctl::base::hiera_merge_values: true
sysctl::base::values:
net.ipv4.ip_forward:
value: '1'
Expand All @@ -74,20 +97,54 @@ sysctl::base::values:
ensure: absent
```

## Original /etc/sysctl.d entries
### Original /etc/sysctl.d entries

When purging, puppet might want to remove files from `/etc/sysctl.d/` which
have not been created by puppet, but need to be present. It's possible to
set the same values for the same keys using puppet, but if the file comes from
an OS package which gets updated, it might re-appear when the package gets
updated. To work around this issue, it's possible to simply manage an
identical file with this module. Example :
When purging, Puppet may want to remove files from `/etc/sysctl.d/` that were
not created by Puppet but need to be present. Setting the same values with
this module is not always enough: if the file comes from an OS package, it
can re-appear when the package is updated. To work around this, manage an
identical file with this module:

```puppet
package { 'libvirt': ensure => installed } ->
sysctl { 'libvirtd':
package { 'libvirt': ensure => installed }
-> sysctl { 'libvirtd':
suffix => '',
source => "puppet:///modules/${module_name}/libvirtd.sysctl",
}
```

## Reference

This module is documented via
[puppet-strings](https://github.com/puppetlabs/puppet-strings). See
[REFERENCE.md](REFERENCE.md) for the full list of classes, defined types and
all of their parameters.

## Limitations

This module supports Puppet 8 (`>= 8.0.0 < 9.0.0`) and `puppetlabs/stdlib`
`>= 9.0.0 < 11.0.0`. The supported OS matrix is defined in `metadata.json`,
and CI runs `pdk validate` and `pdk test unit`.

* RedHat 8, 9, 10
* Rocky 8, 9, 10
* SLES 12, 15
* Ubuntu 20.04, 22.04, 24.04
* Debian 11, 12

## Development

This module is managed with [PDK](https://www.puppet.com/docs/pdk). Before
submitting changes, run the validators and unit tests:

```bash
pdk validate
pdk test unit
```

Keep `REFERENCE.md` in sync by regenerating it whenever parameters or their
documentation change. Never edit it by hand:

```bash
pdk bundle exec puppet strings generate --format markdown
```
Loading
Loading