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

little code modernization #57

Merged
merged 2 commits into from
Jun 12, 2024
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: 2 additions & 1 deletion data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
54 changes: 37 additions & 17 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,17 +61,19 @@

if $manage_limits_file {
file { $limits_file:
ensure => 'file',
ensure => file,
owner => $limits_file_owner,
group => $limits_file_group,
mode => $limits_file_mode,
content => template("limits/${limits_template}.erb"),
}
}

$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,
}
}
}
}
32 changes: 15 additions & 17 deletions manifests/limits.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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#<domain> <type> <item> <value>\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',
})
}
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system CentOS 8
"name": "saz-limits",
"version": "4.0.1",
"author": "saz",
Expand Down Expand Up @@ -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"
Expand Down