From 130258520fa1cd6213d75b28f7f26f49461acd4f Mon Sep 17 00:00:00 2001 From: Lightning Date: Tue, 11 Jun 2024 18:27:22 +0200 Subject: [PATCH 1/2] add puppetlabs/stdlib dependency --- metadata.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/metadata.json b/metadata.json index 2aaf23e..f31ffc1 100644 --- a/metadata.json +++ b/metadata.json @@ -58,6 +58,10 @@ } ], "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 9.0.0 < 10.0.0" + }, { "name": "puppetlabs/concat", "version_requirement": ">= 7.3.0 < 10.0.0" From 4f47041b838c7eb7cd9fb0834a50bf7d1cad9810 Mon Sep 17 00:00:00 2001 From: Lightning Date: Tue, 11 Jun 2024 18:28:27 +0200 Subject: [PATCH 2/2] modernize code --- data/common.yaml | 3 ++- manifests/init.pp | 54 +++++++++++++++++++++++++++++++-------------- manifests/limits.pp | 32 +++++++++++++-------------- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/data/common.yaml b/data/common.yaml index 3638cec..ebba0b6 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -3,7 +3,6 @@ lookup_options: limits::entries: merge: deep -limits::entries: {} limits::limits_dir: /etc/security/limits.d limits::manage_limits_d_dir: true limits::purge_limits_d_dir: true @@ -18,3 +17,5 @@ limits::limits_file_mode: '0644' # until a specific tempalte for each OS and/or major OS version # is supplied. limits::limits_template: 'generic' + +limits::entries: null diff --git a/manifests/init.pp b/manifests/init.pp index 3da7cb8..6ca3557 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -6,33 +6,51 @@ # @example # include limits # +# @param limits_dir +# Directory for individual limits config files +# +# @param manage_limits_d_dir +# Manage $limits_dir itself +# +# @param purge_limits_d_dir +# Purge $limits_dir +# +# @param limits_file +# Basic limits configuration file +# +# @param manage_limits_file +# Manage $limits_file +# # @param limits_file_owner -# The owner of the limits.conf file. +# Owner of $limits_file # # @param limits_file_group -# The group of the limits.conf file. +# Group $limits_file # # @param limits_file_mode -# The mode of the limits.conf file. +# Mode $limits_file # # @param limits_template -# The name of the template to use for ${limits_file +# Name of the template to use for $limits_file +# +# @param entries +# limits configuration file(s) entries # class limits ( - Hash $entries, - String $limits_dir, + String[1] $limits_dir, Boolean $manage_limits_d_dir, Boolean $purge_limits_d_dir, - String $limits_file = $limits::limits_file, - Boolean $manage_limits_file = false, - String[1] $limits_file_owner = $limits::limits_file_owner, - String[1] $limits_file_group = $limits::limits_file_group, - String[1] $limits_file_mode = $limits::limits_file_mode, - Optional[String] $limits_template = $limits::limits_template, + String[1] $limits_file, + Boolean $manage_limits_file, + String[1] $limits_file_owner, + String[1] $limits_file_group, + String[1] $limits_file_mode, + String[1] $limits_template, + Optional[Hash[String[1], Hash[Pattern[/\A[a-z][a-z0-9_]*\Z/], Data], 1]] $entries, ) { if $manage_limits_d_dir { file { $limits_dir: - ensure => 'directory', + ensure => directory, owner => 'root', group => 'root', force => true, @@ -43,7 +61,7 @@ if $manage_limits_file { file { $limits_file: - ensure => 'file', + ensure => file, owner => $limits_file_owner, group => $limits_file_group, mode => $limits_file_mode, @@ -51,9 +69,11 @@ } } - $entries.each | String $e_name, Hash $e_params | { - limits::limits { $e_name: - * => $e_params, + if $entries !~ Undef { + each($entries) | $e_name, $e_params | { + limits::limits { $e_name: + * => $e_params, + } } } } diff --git a/manifests/limits.pp b/manifests/limits.pp index e57462c..880f2cc 100644 --- a/manifests/limits.pp +++ b/manifests/limits.pp @@ -23,13 +23,13 @@ # Manages: # limit file in limits.d with the values provided define limits::limits ( - Enum['absent', 'present'] $ensure = present, - Optional[String] $user = undef, - Optional[String] $limit_type = undef, - Variant[Integer,String,Undef] $hard = undef, - Variant[Integer,String,Undef] $soft = undef, - Variant[Integer,String,Undef] $both = undef, - Optional[String] $target = undef, + Enum['absent', 'present'] $ensure = present, + Optional[String[1]] $user = undef, + Optional[String[1]] $limit_type = undef, + Optional[Variant[Integer, String]] $hard = undef, + Optional[Variant[Integer, String]] $soft = undef, + Optional[Variant[Integer, String]] $both = undef, + Optional[String[1]] $target = undef, ) { include limits @@ -65,22 +65,20 @@ } } - if (!defined(Concat[$target_file])) { - concat { $target_file: - ensure => $ensure, - owner => 'root', - group => 'root', - } - - concat::fragment { "top_${target_file}": + ensure_resource('concat::fragment', "top_${target_file}", { target => $target_file, content => "# Managed by Puppet\n\n# \n", order => '01', - } - } + }) concat::fragment { "${real_user}_${real_type}": target => $target_file, content => template('limits/limits.erb'), } + + ensure_resource('concat', $target_file, { + ensure => $ensure, + owner => 'root', + group => 'root', + }) }