Skip to content

Commit 6da5bc9

Browse files
authored
Merge pull request #223 from bastelfreak/hiera
Add additional hash parameters for defined types
2 parents 8a7c8a9 + 4e47d96 commit 6da5bc9

File tree

3 files changed

+137
-3
lines changed

3 files changed

+137
-3
lines changed

REFERENCE.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ This module allows triggering systemd commands once for all modules
6060
The following parameters are available in the `systemd` class:
6161

6262
* [`service_limits`](#service_limits)
63+
* [`networks`](#networks)
64+
* [`timers`](#timers)
65+
* [`tmpfiles`](#tmpfiles)
66+
* [`unit_files`](#unit_files)
6367
* [`manage_resolved`](#manage_resolved)
6468
* [`resolved_ensure`](#resolved_ensure)
6569
* [`dns`](#dns)
@@ -100,13 +104,45 @@ The following parameters are available in the `systemd` class:
100104

101105
##### <a name="service_limits"></a>`service_limits`
102106

103-
Data type: `Hash[String,Hash[String, Any]]`
107+
Data type: `Hash[String[1],Hash[String[1], Any]]`
104108

105109
May be passed a resource hash suitable for passing directly into the
106110
``create_resources()`` function as called on ``systemd::service_limits``
107111

108112
Default value: `{}`
109113

114+
##### <a name="networks"></a>`networks`
115+
116+
Data type: `Hash[String[1],Hash[String[1], Any]]`
117+
118+
Hash of `systemd::network` resources
119+
120+
Default value: `{}`
121+
122+
##### <a name="timers"></a>`timers`
123+
124+
Data type: `Hash[String[1],Hash[String[1], Any]]`
125+
126+
Hash of `systemd::timer` resources
127+
128+
Default value: `{}`
129+
130+
##### <a name="tmpfiles"></a>`tmpfiles`
131+
132+
Data type: `Hash[String[1],Hash[String[1], Any]]`
133+
134+
Hash of `systemd::tmpfile` resources
135+
136+
Default value: `{}`
137+
138+
##### <a name="unit_files"></a>`unit_files`
139+
140+
Data type: `Hash[String[1],Hash[String[1], Any]]`
141+
142+
Hash of `systemd::unit_file` resources
143+
144+
Default value: `{}`
145+
110146
##### <a name="manage_resolved"></a>`manage_resolved`
111147

112148
Data type: `Boolean`

manifests/init.pp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
# May be passed a resource hash suitable for passing directly into the
77
# ``create_resources()`` function as called on ``systemd::service_limits``
88
#
9+
# @param networks
10+
# Hash of `systemd::network` resources
11+
#
12+
# @param timers
13+
# Hash of `systemd::timer` resources
14+
#
15+
# @param tmpfiles
16+
# Hash of `systemd::tmpfile` resources
17+
#
18+
# @param unit_files
19+
# Hash of `systemd::unit_file` resources
20+
#
921
# @param manage_resolved
1022
# Manage the systemd resolver
1123
#
@@ -130,7 +142,11 @@
130142
#
131143
class systemd (
132144
Hash[String,String] $accounting,
133-
Hash[String,Hash[String, Any]] $service_limits = {},
145+
Hash[String[1],Hash[String[1], Any]] $service_limits = {},
146+
Hash[String[1],Hash[String[1], Any]] $networks = {},
147+
Hash[String[1],Hash[String[1], Any]] $timers = {},
148+
Hash[String[1],Hash[String[1], Any]] $tmpfiles = {},
149+
Hash[String[1],Hash[String[1], Any]] $unit_files = {},
134150
Boolean $manage_resolved = false,
135151
Enum['stopped','running'] $resolved_ensure = 'running',
136152
Optional[Variant[Array[String],String]] $dns = undef,
@@ -168,7 +184,31 @@
168184
Hash $dropin_files = {},
169185
Hash $udev_rules = {},
170186
) {
171-
create_resources('systemd::service_limits', $service_limits)
187+
$service_limits.each |$service_limit, $service_limit_data| {
188+
systemd::service_limits { $service_limit:
189+
* => $service_limit_data,
190+
}
191+
}
192+
$networks.each |$network, $network_data| {
193+
systemd::network { $network:
194+
* => $network_data,
195+
}
196+
}
197+
$timers.each |$timer, $timer_data| {
198+
systemd::timer { $timer:
199+
* => $timer_data,
200+
}
201+
}
202+
$tmpfiles.each |$tmpfile, $tmpfile_data| {
203+
systemd::tmpfile { $tmpfile:
204+
* => $tmpfile_data,
205+
}
206+
}
207+
$unit_files.each |$unit_file, $unit_file_data| {
208+
systemd::unit_file { $unit_file:
209+
* => $unit_file_data,
210+
}
211+
}
172212

173213
if $manage_resolved and $facts['systemd_internal_services'] and $facts['systemd_internal_services']['systemd-resolved.service'] {
174214
contain systemd::resolved

spec/classes/init_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,65 @@
179179
it { is_expected.to compile.with_all_deps }
180180
it { is_expected.to contain_systemd__service_limits('openstack-nova-compute.service').with_limits('LimitNOFILE' => 32_768) }
181181
end
182+
context 'when passing networks' do
183+
let :params do
184+
{
185+
networks: { 'uplink.network' => { 'content' => 'foo' }, 'uplink.netdev' => { 'content' => 'bar' }, },
186+
}
187+
end
188+
189+
it { is_expected.to compile.with_all_deps }
190+
it { is_expected.to contain_systemd__network('uplink.network').with_content('foo') }
191+
it { is_expected.to contain_systemd__network('uplink.netdev').with_content('bar') }
192+
it { is_expected.to contain_file('/etc/systemd/network/uplink.network') }
193+
it { is_expected.to contain_file('/etc/systemd/network/uplink.netdev') }
194+
it { is_expected.to have_systemd__network_resource_count(2) }
195+
end
196+
context 'when passing timers' do
197+
let :params do
198+
{
199+
timers: { 'first.timer' => { 'timer_content' => 'foo' }, 'second.timer' => { 'timer_content' => 'bar' }, },
200+
}
201+
end
182202

203+
it { is_expected.to compile.with_all_deps }
204+
it { is_expected.to contain_systemd__timer('first.timer').with_timer_content('foo') }
205+
it { is_expected.to contain_systemd__timer('second.timer').with_timer_content('bar') }
206+
it { is_expected.to contain_systemd__unit_file('first.timer').with_content('foo') }
207+
it { is_expected.to contain_systemd__unit_file('second.timer').with_content('bar') }
208+
it { is_expected.to contain_file('/etc/systemd/system/first.timer') }
209+
it { is_expected.to contain_file('/etc/systemd/system/second.timer') }
210+
it { is_expected.to have_systemd__timer_resource_count(2) }
211+
it { is_expected.to have_systemd__unit_file_resource_count(2) }
212+
end
213+
context 'when passing tmpfiles' do
214+
let :params do
215+
{
216+
tmpfiles: { 'first_tmpfile.conf' => { 'content' => 'foo' }, 'second_tmpfile.conf' => { 'content' => 'bar' }, },
217+
}
218+
end
219+
220+
it { is_expected.to compile.with_all_deps }
221+
it { is_expected.to contain_systemd__tmpfile('first_tmpfile.conf').with_content('foo') }
222+
it { is_expected.to contain_systemd__tmpfile('second_tmpfile.conf').with_content('bar') }
223+
it { is_expected.to contain_file('/etc/tmpfiles.d/first_tmpfile.conf') }
224+
it { is_expected.to contain_file('/etc/tmpfiles.d/second_tmpfile.conf') }
225+
it { is_expected.to have_systemd__tmpfile_resource_count(2) }
226+
end
227+
context 'when passing unit_files' do
228+
let :params do
229+
{
230+
unit_files: { 'first.service' => { 'content' => 'foo' }, 'second.service' => { 'content' => 'bar' }, },
231+
}
232+
end
233+
234+
it { is_expected.to compile.with_all_deps }
235+
it { is_expected.to contain_systemd__unit_file('first.service').with_content('foo') }
236+
it { is_expected.to contain_systemd__unit_file('second.service').with_content('bar') }
237+
it { is_expected.to contain_file('/etc/systemd/system/first.service') }
238+
it { is_expected.to contain_file('/etc/systemd/system/second.service') }
239+
it { is_expected.to have_systemd__unit_file_resource_count(2) }
240+
end
183241
context 'when managing Accounting options' do
184242
let :params do
185243
{

0 commit comments

Comments
 (0)