Skip to content

Commit

Permalink
modernize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning- committed Jun 12, 2024
1 parent 1302585 commit 4f47041
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
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',
})
}

0 comments on commit 4f47041

Please sign in to comment.