Skip to content

Commit 25eb284

Browse files
authored
Merge pull request #30 from crayfishx/feature/hiera5
refactored for Puppet 4 / Hiera 5
2 parents e996d70 + 59f93c8 commit 25eb284

File tree

10 files changed

+95
-65
lines changed

10 files changed

+95
-65
lines changed

.travis.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ script: 'bundle exec metadata-json-lint metadata.json && bundle exec rake valida
44
matrix:
55
fast_finish: true
66
include:
7-
- rvm: 1.9.3
8-
env: PUPPET_GEM_VERSION="~> 3" STRICT_VARIABLES="yes"
9-
- rvm: 1.9.3
10-
env: PUPPET_GEM_VERSION="~> 3" STRICT_VARIABLES="yes" FUTURE_PARSER="yes"
11-
- rvm: 2.1
12-
env: PUPPET_GEM_VERSION="~> 3" STRICT_VARIABLES="yes"
13-
- rvm: 2.1
14-
env: PUPPET_GEM_VERSION="~> 3" STRICT_VARIABLES="yes" FUTURE_PARSER="yes"
15-
- rvm: 2.2
16-
env: PUPPET_GEM_VERSION="~> 4" STRICT_VARIABLES="yes"
17-
- rvm: 2.3.1
18-
env: PUPPET_GEM_VERSION="~> 4" STRICT_VARIABLES="yes"
19-
- rvm: 2.3.1
20-
env: PUPPET_GEM_VERSION="~> 4" STRICT_VARIABLES="yes" FORGEDEPLOY=true
7+
- rvm: 2.1.9
8+
env: PUPPET_VERSION="~> 4.9.0" STRICT_VARIABLES="yes"
9+
- rvm: 2.1.9
10+
env: PUPPET_VERSION="~> 4.10.0" STRICT_VARIABLES="yes"
11+
- rvm: 2.4.1
12+
env: PUPPET_VERSION="~> 5.0.0" STRICT_VARIABLES="yes"
13+
- rvm: 2.4.1
14+
env: PUPPET_VERSION="~> 5.1.0" STRICT_VARIABLES="yes"
15+
- rvm: 2.4.1
16+
env: PUPPET_VERSION="~> 5.2.0" STRICT_VARIABLES="yes"
17+
- rvm: 2.4.1
18+
env: PUPPET_VERSION="~> 5.3.0" STRICT_VARIABLES="yes" FORGEDEPLOY=true
19+
2120
notifications:
2221
email: false
2322
deploy:

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ It creates files in `/etc/security/limits.d` and does not manage the file `/etc/
1919
limits::limits{'root/nofile': both => 1048576; }
2020
```
2121

22+
### Parameters
23+
24+
* `purge_limits_d_dir` (Boolean, default: true) Whether or not to purge the limits.d directory
25+
* `manage_limits_d_dir` (Boolean, default: true) Whether or not to manage the limits.d directory
26+
* `limits_dir`: (String) The location of the limits.d directory
27+
* `entries`: (Hash) A hash of limits entries, keys should be the name and the value as a hash made up of;
28+
* `ensure`: (String, default present) Values can be absent or present
29+
* `user`: (String) The user that the limit applies to
30+
* `limit_type` (String) The limit type
31+
* `hard`: (Integer) the hard value
32+
* `soft`: (Integer) the soft value
33+
* `both`: (Integer) the value of both soft and hard
34+
35+
2236
### Using hiera
2337

2438
Puppet:
@@ -39,9 +53,23 @@ Hiera:
3953
4054
## Compatibility
4155
42-
This module has been tested to work with Puppet v3 (with and without the future
43-
parser) and v4 with Ruby versions 1.8.7 (Puppet v3 only), 1.9.3, 2.0.0 and
44-
2.1.0.
56+
### Puppet 4.9+
57+
58+
This module is compatible with Puppet 4.9+, and Puppet 5.0+
59+
60+
### Puppet 4.0 - 4.8
61+
62+
To use this module with previous versions of Puppet 4 (prior to Hiera 5) you should update your Hiera data to include the following
63+
64+
```yaml
65+
---
66+
limits::limits_dir: /etc/security/limits.d
67+
68+
lookup_options:
69+
limits::entries:
70+
merge: deep
71+
```
72+
4573
4674
### Purge limits.d directory
4775

data/common.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
limits::limits_dir: /etc/security/limits.d
3+
4+
lookup_options:
5+
limits::entries:
6+
merge: deep

hiera.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
version: 5
3+
defaults:
4+
datadir: data
5+
data_hash: yaml_data
6+
hierarchy:
7+
- name: "common"
8+
path: "common.yaml"

manifests/init.pp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# == Class: limits
22
#
33
class limits (
4-
$purge_limits_d_dir = true,
5-
$entries_hash = hiera_hash(limits::entries, {}),
6-
$manage_limits_d_dir = true,
7-
) inherits ::limits::params {
4+
String $limits_dir,
5+
Boolean $purge_limits_d_dir = true,
6+
Boolean $manage_limits_d_dir = true,
7+
Hash $entries = {},
8+
) {
89

9-
if $manage_limits_d_dir == true {
10-
file { $limits::params::limits_dir:
10+
if $manage_limits_d_dir {
11+
file { $limits_dir:
1112
ensure => 'directory',
1213
owner => 'root',
1314
group => 'root',
@@ -18,8 +19,11 @@
1819
}
1920

2021
### Create instances for integration with Hiera
21-
if $entries_hash != {} {
22-
validate_hash($entries_hash)
23-
create_resources(limits::limits, $entries_hash)
22+
23+
$entries.each | String $e_name, Hash $e_params | {
24+
limits::limits { $e_name:
25+
* => $e_params,
26+
}
2427
}
28+
2529
}

manifests/limits.pp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
# Manages:
1919
# limit file in limits.d with the values provided
2020
define limits::limits(
21-
$ensure = present,
22-
$user = undef,
23-
$limit_type = undef,
24-
$hard = undef,
25-
$soft = undef,
26-
$both = undef,
21+
Enum['absent', 'present'] $ensure = present,
22+
Optional[String] $user = undef,
23+
Optional[String] $limit_type = undef,
24+
Optional[Integer] $hard = undef,
25+
Optional[Integer] $soft = undef,
26+
Optional[Integer] $both = undef,
2727
) {
2828

2929
include ::limits
@@ -45,12 +45,12 @@
4545
}
4646

4747
if $title =~ /\.conf$/ {
48-
$target_file = "${limits::params::limits_dir}/${title}"
48+
$target_file = "${limits::limits_dir}/${title}"
4949
} else {
5050
if $real_user == '*' {
51-
$target_file = "${limits::params::limits_dir}/default_${real_type}.conf"
51+
$target_file = "${limits::limits_dir}/default_${real_type}.conf"
5252
} else {
53-
$target_file = "${limits::params::limits_dir}/${real_user}_${real_type}.conf"
53+
$target_file = "${limits::limits_dir}/${real_user}_${real_type}.conf"
5454
}
5555
}
5656

manifests/params.pp

Lines changed: 0 additions & 10 deletions
This file was deleted.

metadata.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@
3232
}
3333
],
3434
"requirements": [
35-
{
36-
"name": "pe",
37-
"version_requirement": ">= 3.2.0 < 5.0.0"
38-
},
3935
{
4036
"name": "puppet",
41-
"version_requirement": ">= 3.0.0 < 5.0.0"
37+
"version_requirement": ">= 4.0.0 < 6.0.0"
4238
}
4339
],
4440
"dependencies": [

spec/classes/limits_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

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

39-
it { should contain_class('limits::params') }
4039

4140
it do
4241
if params[:manage_limits_d_dir] == false

spec/defines/limits_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
:user => 'username',
1515
:limit_type => 'nofile',
1616
:ensure => 'present',
17-
:hard => '16384',
18-
:soft => '16384'
17+
:hard => 16384,
18+
:soft => 16384
1919
}
2020
end
2121

@@ -26,8 +26,8 @@
2626
:user => 'username',
2727
:limit_type => 'nofile',
2828
:ensure => 'present',
29-
:hard => '16384',
30-
:soft => '16384'
29+
:hard => 16384,
30+
:soft => 16384
3131
})
3232
}
3333
it { should contain_file(filename).with({
@@ -45,8 +45,8 @@
4545
:user => 'username',
4646
:limit_type => 'nofile',
4747
:ensure => 'present',
48-
:hard => '16384',
49-
:soft => '16384'
48+
:hard => 16384,
49+
:soft => 16384
5050
})
5151
}
5252
it { should contain_file(filename).with({
@@ -64,8 +64,8 @@
6464
:user => 'username',
6565
:limit_type => 'nofile',
6666
:ensure => 'absent',
67-
:hard => '16384',
68-
:soft => '16384'
67+
:hard => 16384,
68+
:soft => 16384
6969
}
7070
end
7171
it { should contain_file(filename).with({
@@ -84,15 +84,15 @@
8484
:user => 'username',
8585
:limit_type => 'nofile',
8686
:ensure => 'present',
87-
:both => '16384'
87+
:both => 16384
8888
}
8989
end
9090
let(:title) { 'username_nofile.conf' }
9191
it { should contain_limits__limits('username_nofile.conf').with({
9292
:user => 'username',
9393
:limit_type => 'nofile',
9494
:ensure => 'present',
95-
:both => '16384'
95+
:both => 16384
9696
})
9797
}
9898
it { should contain_file(filename).with({
@@ -110,7 +110,7 @@
110110
let(:title) { '*/nofile' }
111111
let :params do
112112
{
113-
:both => '16384'
113+
:both => 16384
114114
}
115115
end
116116
it { should compile.with_all_deps }
@@ -127,7 +127,7 @@
127127
let(:title) { 'root/nofile' }
128128
let :params do
129129
{
130-
:hard => '12345'
130+
:hard => 12345
131131
}
132132
end
133133
it { should contain_file('/etc/security/limits.d/root_nofile.conf').with({
@@ -146,7 +146,7 @@
146146
let :params do
147147
{
148148
:limit_type => 'nofile',
149-
:both => '16384'
149+
:both => 16384
150150
}
151151
end
152152
it { should compile.and_raise_error(/when not using the title pattern/) }
@@ -156,7 +156,7 @@
156156
let :params do
157157
{
158158
:user => 'foo',
159-
:both => '16384'
159+
:both => 16384
160160
}
161161
end
162162
it { should compile.and_raise_error(/when not using the title pattern/) }

0 commit comments

Comments
 (0)