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
27 changes: 13 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ script: 'bundle exec metadata-json-lint metadata.json && bundle exec rake valida
matrix:
fast_finish: true
include:
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3" STRICT_VARIABLES="yes"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3" STRICT_VARIABLES="yes" FUTURE_PARSER="yes"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 3" STRICT_VARIABLES="yes"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 3" STRICT_VARIABLES="yes" FUTURE_PARSER="yes"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 4" STRICT_VARIABLES="yes"
- rvm: 2.3.1
env: PUPPET_GEM_VERSION="~> 4" STRICT_VARIABLES="yes"
- rvm: 2.3.1
env: PUPPET_GEM_VERSION="~> 4" STRICT_VARIABLES="yes" FORGEDEPLOY=true
- rvm: 2.1.9
env: PUPPET_VERSION="~> 4.9.0" STRICT_VARIABLES="yes"
- rvm: 2.1.9
env: PUPPET_VERSION="~> 4.10.0" STRICT_VARIABLES="yes"
- rvm: 2.4.1
env: PUPPET_VERSION="~> 5.0.0" STRICT_VARIABLES="yes"
- rvm: 2.4.1
env: PUPPET_VERSION="~> 5.1.0" STRICT_VARIABLES="yes"
- rvm: 2.4.1
env: PUPPET_VERSION="~> 5.2.0" STRICT_VARIABLES="yes"
- rvm: 2.4.1
env: PUPPET_VERSION="~> 5.3.0" STRICT_VARIABLES="yes" FORGEDEPLOY=true

notifications:
email: false
deploy:
Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ It creates files in `/etc/security/limits.d` and does not manage the file `/etc/
limits::limits{'root/nofile': both => 1048576; }
```

### Parameters

* `purge_limits_d_dir` (Boolean, default: true) Whether or not to purge the limits.d directory
* `manage_limits_d_dir` (Boolean, default: true) Whether or not to manage the limits.d directory
* `limits_dir`: (String) The location of the limits.d directory
* `entries`: (Hash) A hash of limits entries, keys should be the name and the value as a hash made up of;
* `ensure`: (String, default present) Values can be absent or present
* `user`: (String) The user that the limit applies to
* `limit_type` (String) The limit type
* `hard`: (Integer) the hard value
* `soft`: (Integer) the soft value
* `both`: (Integer) the value of both soft and hard


### Using hiera

Puppet:
Expand All @@ -39,9 +53,23 @@ Hiera:

## Compatibility

This module has been tested to work with Puppet v3 (with and without the future
parser) and v4 with Ruby versions 1.8.7 (Puppet v3 only), 1.9.3, 2.0.0 and
2.1.0.
### Puppet 4.9+

This module is compatible with Puppet 4.9+, and Puppet 5.0+

### Puppet 4.0 - 4.8

To use this module with previous versions of Puppet 4 (prior to Hiera 5) you should update your Hiera data to include the following

```yaml
---
limits::limits_dir: /etc/security/limits.d

lookup_options:
limits::entries:
merge: deep
```


### Purge limits.d directory

Expand Down
6 changes: 6 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
limits::limits_dir: /etc/security/limits.d

lookup_options:
limits::entries:
merge: deep
8 changes: 8 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
version: 5
defaults:
datadir: data
data_hash: yaml_data
hierarchy:
- name: "common"
path: "common.yaml"
22 changes: 13 additions & 9 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# == Class: limits
#
class limits (
$purge_limits_d_dir = true,
$entries_hash = hiera_hash(limits::entries, {}),
$manage_limits_d_dir = true,
) inherits ::limits::params {
String $limits_dir,
Boolean $purge_limits_d_dir = true,
Boolean $manage_limits_d_dir = true,
Hash $entries = {},
) {

if $manage_limits_d_dir == true {
file { $limits::params::limits_dir:
if $manage_limits_d_dir {
file { $limits_dir:
ensure => 'directory',
owner => 'root',
group => 'root',
Expand All @@ -18,8 +19,11 @@
}

### Create instances for integration with Hiera
if $entries_hash != {} {
validate_hash($entries_hash)
create_resources(limits::limits, $entries_hash)

$entries.each | String $e_name, Hash $e_params | {
limits::limits { $e_name:
* => $e_params,
}
}

}
18 changes: 9 additions & 9 deletions manifests/limits.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# Manages:
# limit file in limits.d with the values provided
define limits::limits(
$ensure = present,
$user = undef,
$limit_type = undef,
$hard = undef,
$soft = undef,
$both = undef,
Enum['absent', 'present'] $ensure = present,
Optional[String] $user = undef,
Optional[String] $limit_type = undef,
Optional[Integer] $hard = undef,
Optional[Integer] $soft = undef,
Optional[Integer] $both = undef,
) {

include ::limits
Expand All @@ -45,12 +45,12 @@
}

if $title =~ /\.conf$/ {
$target_file = "${limits::params::limits_dir}/${title}"
$target_file = "${limits::limits_dir}/${title}"
} else {
if $real_user == '*' {
$target_file = "${limits::params::limits_dir}/default_${real_type}.conf"
$target_file = "${limits::limits_dir}/default_${real_type}.conf"
} else {
$target_file = "${limits::params::limits_dir}/${real_user}_${real_type}.conf"
$target_file = "${limits::limits_dir}/${real_user}_${real_type}.conf"
}
}

Expand Down
10 changes: 0 additions & 10 deletions manifests/params.pp

This file was deleted.

6 changes: 1 addition & 5 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@
}
],
"requirements": [
{
"name": "pe",
"version_requirement": ">= 3.2.0 < 5.0.0"
},
{
"name": "puppet",
"version_requirement": ">= 3.0.0 < 5.0.0"
"version_requirement": ">= 4.0.0 < 6.0.0"
}
],
"dependencies": [
Expand Down
1 change: 0 additions & 1 deletion spec/classes/limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

describe "on supported osfamily: #{osfamily}" do

it { should contain_class('limits::params') }

it do
if params[:manage_limits_d_dir] == false
Expand Down
28 changes: 14 additions & 14 deletions spec/defines/limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
:user => 'username',
:limit_type => 'nofile',
:ensure => 'present',
:hard => '16384',
:soft => '16384'
:hard => 16384,
:soft => 16384
}
end

Expand All @@ -26,8 +26,8 @@
:user => 'username',
:limit_type => 'nofile',
:ensure => 'present',
:hard => '16384',
:soft => '16384'
:hard => 16384,
:soft => 16384
})
}
it { should contain_file(filename).with({
Expand All @@ -45,8 +45,8 @@
:user => 'username',
:limit_type => 'nofile',
:ensure => 'present',
:hard => '16384',
:soft => '16384'
:hard => 16384,
:soft => 16384
})
}
it { should contain_file(filename).with({
Expand All @@ -64,8 +64,8 @@
:user => 'username',
:limit_type => 'nofile',
:ensure => 'absent',
:hard => '16384',
:soft => '16384'
:hard => 16384,
:soft => 16384
}
end
it { should contain_file(filename).with({
Expand All @@ -84,15 +84,15 @@
:user => 'username',
:limit_type => 'nofile',
:ensure => 'present',
:both => '16384'
:both => 16384
}
end
let(:title) { 'username_nofile.conf' }
it { should contain_limits__limits('username_nofile.conf').with({
:user => 'username',
:limit_type => 'nofile',
:ensure => 'present',
:both => '16384'
:both => 16384
})
}
it { should contain_file(filename).with({
Expand All @@ -110,7 +110,7 @@
let(:title) { '*/nofile' }
let :params do
{
:both => '16384'
:both => 16384
}
end
it { should compile.with_all_deps }
Expand All @@ -127,7 +127,7 @@
let(:title) { 'root/nofile' }
let :params do
{
:hard => '12345'
:hard => 12345
}
end
it { should contain_file('/etc/security/limits.d/root_nofile.conf').with({
Expand All @@ -146,7 +146,7 @@
let :params do
{
:limit_type => 'nofile',
:both => '16384'
:both => 16384
}
end
it { should compile.and_raise_error(/when not using the title pattern/) }
Expand All @@ -156,7 +156,7 @@
let :params do
{
:user => 'foo',
:both => '16384'
:both => 16384
}
end
it { should compile.and_raise_error(/when not using the title pattern/) }
Expand Down