diff --git a/.fixtures.yml b/.fixtures.yml index 8ecf049..ff6a7ae 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,6 +2,3 @@ fixtures: repositories: stdlib: repo: "https://github.com/puppetlabs/puppetlabs-stdlib.git" - symlinks: - sysctl: "#{source_dir}" - diff --git a/.github/workflows/run-pdk-tests-on-puppet-7.yml b/.github/workflows/run-pdk-tests-on-puppet-7.yml deleted file mode 100644 index 1b13f18..0000000 --- a/.github/workflows/run-pdk-tests-on-puppet-7.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Run PDK tests on Puppet 7.x - -on: - - push - - pull_request - -jobs: - validate-7: - runs-on: ubuntu-latest - steps: - - name: Clone repository - uses: actions/checkout@v2 - - - name: Run pdk validate - uses: puppets-epic-show-theatre/action-pdk-validate@v1 - with: - puppet-version: "7" - # [optional] A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5". - # pe-version: "" - # [optional] A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1". - - test-7: - runs-on: ubuntu-latest - steps: - - name: Clone repository - uses: actions/checkout@v2 - - - name: Run unit tests - uses: puppets-epic-show-theatre/action-pdk-test-unit@v1 - with: - puppet-version: "7" - # [optional] A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5". - # pe-version: "" - # [optional] A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1". diff --git a/.github/workflows/run-pdk-tests-on-puppet-8.yml b/.github/workflows/run-pdk-tests-on-puppet-8.yml index 12460e0..c0b10f0 100644 --- a/.github/workflows/run-pdk-tests-on-puppet-8.yml +++ b/.github/workflows/run-pdk-tests-on-puppet-8.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 3f15512..2803e56 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ /spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store @@ -26,3 +27,9 @@ .envrc /inventory.yaml /spec/fixtures/litmus_inventory.yaml +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log diff --git a/.pdkignore b/.pdkignore index 584438f..84684be 100644 --- a/.pdkignore +++ b/.pdkignore @@ -19,6 +19,7 @@ /spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store @@ -26,9 +27,16 @@ .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 diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece..9e15c6e 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -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 diff --git a/.rubocop.yml b/.rubocop.yml index 5be1f9f..21b82b9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,7 @@ require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true TargetRubyVersion: '2.6' Include: @@ -527,6 +528,8 @@ Lint/DuplicateBranch: Enabled: false Lint/DuplicateMagicComment: Enabled: false +Lint/DuplicateMatchPattern: + Enabled: false Lint/DuplicateRegexpCharacterClassElement: Enabled: false Lint/EmptyBlock: @@ -643,6 +646,8 @@ Style/ComparableClamp: Enabled: false Style/ConcatArrayLiterals: Enabled: false +Style/DataInheritance: + Enabled: false Style/DirEmpty: Enabled: false Style/DocumentDynamicEvalDefinition: @@ -711,6 +716,8 @@ Style/RedundantHeredocDelimiterQuotes: Enabled: false Style/RedundantInitialize: Enabled: false +Style/RedundantLineContinuation: + Enabled: false Style/RedundantSelfAssignmentBranch: Enabled: false Style/RedundantStringEscape: diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 2f1e4f7..6da8d47 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,6 @@ { "recommendations": [ "puppet.puppet-vscode", - "rebornix.Ruby" + "Shopify.ruby-lsp" ] } diff --git a/Gemfile b/Gemfile index add1873..dc6cbe0 100644 --- a/Gemfile +++ b/Gemfile @@ -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'] diff --git a/README.md b/README.md index 66a365e..7e3a01d 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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 +``` diff --git a/REFERENCE.md b/REFERENCE.md new file mode 100644 index 0000000..3164fd6 --- /dev/null +++ b/REFERENCE.md @@ -0,0 +1,205 @@ +# Reference + + + +## Table of Contents + +### Classes + +#### Public Classes + +* [`sysctl::base`](#sysctl--base): Common part for the sysctl definition. Not meant to be used on its own. + +#### Private Classes + +* `sysctl::params` + +### Defined types + +* [`sysctl`](#sysctl): Manage sysctl variable values. + +## Classes + +### `sysctl::base` + +Common part for the sysctl definition. Not meant to be used on its own. + +#### Parameters + +The following parameters are available in the `sysctl::base` class: + +* [`purge`](#-sysctl--base--purge) +* [`values`](#-sysctl--base--values) +* [`hiera_merge_values`](#-sysctl--base--hiera_merge_values) +* [`symlink99`](#-sysctl--base--symlink99) +* [`sysctl_dir`](#-sysctl--base--sysctl_dir) +* [`sysctl_dir_path`](#-sysctl--base--sysctl_dir_path) +* [`sysctl_dir_owner`](#-sysctl--base--sysctl_dir_owner) +* [`sysctl_dir_group`](#-sysctl--base--sysctl_dir_group) +* [`sysctl_dir_mode`](#-sysctl--base--sysctl_dir_mode) + +##### `purge` + +Data type: `Boolean` + +Boolean to choose if $sysctl_dir_path should get purged. + +Default value: `false` + +##### `values` + +Data type: `Hash` + +Hash of sysctl keys and their values to managed. + +Default value: `{}` + +##### `hiera_merge_values` + +Data type: `Boolean` + +Boolean to choose if $values to be used should be searched in hiera. + +Default value: `false` + +##### `symlink99` + +Data type: `Boolean` + +Boolean to choose if 99-sysctl.conf should be created. + +Default value: `$sysctl::params::symlink99` + +##### `sysctl_dir` + +Data type: `Boolean` + +Boolean to choose if $sysctl_dir_path should be managed. + +Default value: `true` + +##### `sysctl_dir_path` + +Data type: `Stdlib::Absolutepath` + +Absolute path of sysctl directory. + +Default value: `'/etc/sysctl.d'` + +##### `sysctl_dir_owner` + +Data type: `String[1]` + +Owner for sysctl directory. + +Default value: `'root'` + +##### `sysctl_dir_group` + +Data type: `String[1]` + +Group for sysctl directory. + +Default value: `'root'` + +##### `sysctl_dir_mode` + +Data type: `Stdlib::Filemode` + +Mode for sysctl directory. + +Default value: `'0755'` + +## Defined types + +### `sysctl` + +Manage sysctl variable values. + +#### Examples + +##### + +```puppet +Sample Usage : +sysctl { 'net.ipv6.bindv6only': value => '1' } +``` + +#### Parameters + +The following parameters are available in the `sysctl` defined type: + +* [`ensure`](#-sysctl--ensure) +* [`value`](#-sysctl--value) +* [`prefix`](#-sysctl--prefix) +* [`suffix`](#-sysctl--suffix) +* [`comment`](#-sysctl--comment) +* [`content`](#-sysctl--content) +* [`source`](#-sysctl--source) +* [`enforce`](#-sysctl--enforce) + +##### `ensure` + +Data type: `Enum['present', 'absent']` + +Whether the variable's value should be 'present' or 'absent'. +Defaults to 'present'. + +Default value: `'present'` + +##### `value` + +Data type: `Optional[String[1]]` + +The value for the sysctl parameter. Mandatory, unless $ensure is 'absent'. + +Default value: `undef` + +##### `prefix` + +Data type: `Optional[String[1]]` + +Optional prefix for the sysctl.d file to be created. Default: none. + +Default value: `undef` + +##### `suffix` + +Data type: `String` + +Optional suffix for the sysctl.d file to be created. Default: '.conf'. + +Default value: `'.conf'` + +##### `comment` + +Data type: `Optional[Variant[Array, String[1]]]` + +Comment(s) to be added to the sysctl.d file. + +Default value: `undef` + +##### `content` + +Data type: `Optional[String[1]]` + +Content for the sysctl.d file to be used instead of the template. + +Default value: `undef` + +##### `source` + +Data type: `Optional[Stdlib::Filesource]` + +Source file for the sysctl.d file to be used instead of the template. + +Default value: `undef` + +##### `enforce` + +Data type: `Boolean` + +Enforce configured value during each run (can't work with custom files). + +Default value: `true` + diff --git a/Rakefile b/Rakefile index 74415a9..31b5930 100644 --- a/Rakefile +++ b/Rakefile @@ -4,85 +4,15 @@ require 'bundler' require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'github_changelog_generator/task' if Gem.loaded_specs.key? 'github_changelog_generator' require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' -def changelog_user - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['author'] - raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator user:#{returnVal}" - returnVal -end - -def changelog_project - return unless Rake.application.top_level_tasks.include? "changelog" - - returnVal = nil - returnVal ||= begin - metadata_source = JSON.load(File.read('metadata.json'))['source'] - metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) - - metadata_source_match && metadata_source_match[1] - end - - raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? - - puts "GitHubChangelogGenerator project:#{returnVal}" - returnVal -end - -def changelog_future_release - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] - raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator future_release:#{returnVal}" - returnVal -end - PuppetLint.configuration.send('disable_relative') - - -if Gem.loaded_specs.key? 'github_changelog_generator' - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? - config.user = "#{changelog_user}" - config.project = "#{changelog_project}" - config.future_release = "#{changelog_future_release}" - config.exclude_labels = ['maintenance'] - config.header = "# Change log\n\nAll 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)." - config.add_pr_wo_labels = true - config.issues = false - config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB" - config.configure_sections = { - "Changed" => { - "prefix" => "### Changed", - "labels" => ["backwards-incompatible"], - }, - "Added" => { - "prefix" => "### Added", - "labels" => ["enhancement", "feature"], - }, - "Fixed" => { - "prefix" => "### Fixed", - "labels" => ["bug", "documentation", "bugfix"], - }, - } - end -else - desc 'Generate a Changelog from GitHub' - task :changelog do - raise < 1.15' - condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" -EOM - end -end +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"] diff --git a/manifests/base.pp b/manifests/base.pp index 5e30838..751fa9a 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -41,12 +41,16 @@ ) inherits sysctl::params { # Hiera support if $hiera_merge_values == true { - $values_real = hiera_hash('sysctl::base::values', {}) + $values_real = lookup('sysctl::base::values', Hash, 'hash', {}) } else { $values_real = $values } - create_resources(sysctl,$values_real) + $values_real.each |String $key, Hash $attrs| { + sysctl { $key: + * => $attrs, + } + } if $sysctl_dir { file { $sysctl_dir_path: diff --git a/manifests/init.pp b/manifests/init.pp index 0d29412..0b6bfc8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -57,7 +57,11 @@ if $content { $file_content = $content } else { - $file_content = template("${module_name}/sysctl.d-file.erb") + $file_content = epp("${module_name}/sysctl.d-file.epp", { + 'title' => $title, + 'value' => $value, + 'comment' => $comment, + }) } if $ensure == 'present' { diff --git a/metadata.json b/metadata.json index 1903570..544a525 100644 --- a/metadata.json +++ b/metadata.json @@ -10,55 +10,60 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.25.0 < 10.0.0" + "version_requirement": ">= 9.0.0 < 11.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "RedHat", "operatingsystemrelease": [ - "5", - "6", - "7", - "8" + "8", + "9", + "10" ] }, { - "operatingsystem": "CentOS", + "operatingsystem": "Rocky", "operatingsystemrelease": [ - "5", - "6", - "7", - "8" + "8", + "9", + "10" ] }, { - "operatingsystem": "Debian", + "operatingsystem": "SLES", "operatingsystemrelease": [ - "6", - "7", - "8" + "12", + "15" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "12", - "14" + "20.04", + "22.04", + "24.04" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "11", + "12" ] } ], "requirements": [ { "name": "puppet", - "version_requirement": ">=2.7.20 < 9.0.0" + "version_requirement": ">= 8.0.0 < 9.0.0" } ], "tags": [ "sysctl", "os" ], - "pdk-version": "3.0.0", - "template-url": "pdk-default#3.0.0", - "template-ref": "tags/3.0.0-0-g056e50d" + "pdk-version": "3.4.0", + "template-url": "https://puppetgit.lx.gic.ericsson.se/puppet/pdk-templates#3.4.0.3", + "template-ref": "tags/3.4.0.3-0-g8fb22fc" } diff --git a/pdk.yaml b/pdk.yaml new file mode 100644 index 0000000..4bef4bd --- /dev/null +++ b/pdk.yaml @@ -0,0 +1,2 @@ +--- +ignore: [] diff --git a/spec/default_facts.yml b/spec/default_facts.yml index f777abf..3346c39 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -2,7 +2,8 @@ # # Facts specified here will override the values provided by rspec-puppet-facts. --- -ipaddress: "172.16.254.254" -ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" +networking: + ip: "172.16.254.254" + ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" + mac: "AA:AA:AA:AA:AA:AA" is_pe: false -macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/init_spec.rb b/spec/defines/init_spec.rb index 419cc06..24498a5 100644 --- a/spec/defines/init_spec.rb +++ b/spec/defines/init_spec.rb @@ -161,7 +161,15 @@ ) end end + context 'with comment set to multi-line string' do + let(:params) { { comment: "test\n ing \n\nend\n" } } + it do + is_expected.to contain_file('/etc/sysctl.d/net.ipv4.ip_forward.conf').with( + content: header + "# test\n# ing\n# \n# end\nnet.ipv4.ip_forward = \n", + ) + end + end context 'with content set to valid testing' do let(:params) { { content: 'testing' } } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61df294..4422884 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,7 +25,8 @@ next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin - default_facts.merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) + require 'deep_merge' + default_facts.deep_merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end @@ -33,7 +34,7 @@ # read default_facts and merge them over what is provided by facterdb default_facts.each do |fact, value| - add_custom_fact fact, value + add_custom_fact fact, value, merge_facts: true end RSpec.configure do |c| diff --git a/templates/sysctl.d-file.epp b/templates/sysctl.d-file.epp new file mode 100644 index 0000000..e8fa77b --- /dev/null +++ b/templates/sysctl.d-file.epp @@ -0,0 +1,17 @@ +<%- | String $title, + Optional[String] $value, + Optional[Variant[Array, String]] $comment, +| -%> +# This file is being maintained by Puppet. +# DO NOT EDIT + +<% if $comment =~ Array { -%> +<% $comment.each |$line| { -%> +# <%= $line %> +<% } -%> +<% } elsif $comment =~ String { -%> +<% $comment.split(/(?<=\n)/).each |$line| { -%> +# <%= $line.strip %> +<% } -%> +<% } -%> +<%= $title %> = <%= $value %> diff --git a/templates/sysctl.d-file.erb b/templates/sysctl.d-file.erb deleted file mode 100644 index 1ae40d7..0000000 --- a/templates/sysctl.d-file.erb +++ /dev/null @@ -1,13 +0,0 @@ -# This file is being maintained by Puppet. -# DO NOT EDIT - -<% if @comment.is_a?(Array) -%> -<% @comment.each do |line| -%> -# <%= line %> -<% end -%> -<% elsif @comment.is_a?(String) -%> -<% @comment.each_line do |line| -%> -# <%= line.strip %> -<% end -%> -<% end -%> -<%= @title %> = <%= @value %>