Skip to content

Commit 63a41e0

Browse files
authored
Merge pull request #436 from traylenator/hiera
Create manage_unit, manage_dropin types from hiera
2 parents 2b8eebf + 14b661c commit 63a41e0

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ systemd::manage_unit { 'myrunner.service':
8282
The parameters `unit_entry`, `service_entry` and `install_entry` populate the
8383
`[Unit]`, `[Service]` and `[Install]` sections of the generated unit file.
8484

85+
Similarly units can be created from hiera yaml files
86+
87+
```yaml
88+
systemd::manage_units:
89+
myservice.service:
90+
unit_entry:
91+
Description: My Customisation
92+
service_entry:
93+
CPUWeight: 2000
94+
```
95+
8596
### drop-in files
8697
8798
Drop-in files are used to add or alter settings of a unit without modifying the
@@ -141,6 +152,20 @@ systemd::manage_dropin { 'myconf.conf':
141152
}
142153
```
143154

155+
Dropins can also be created similarly via yaml
156+
157+
```yaml
158+
systemd::manage_dropins:
159+
myconf.conf:
160+
ensure: present
161+
unit: myservice.service
162+
service_entry:
163+
Type: oneshot
164+
ExecStart:
165+
- ''
166+
- '/usr/bin/doit.sh'
167+
```
168+
144169
The filename of the drop in. The full path is determined using the path, unit and this filename.
145170
146171
### modules-load.d

REFERENCE.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ The following parameters are available in the `systemd` class:
133133
* [`logind_settings`](#-systemd--logind_settings)
134134
* [`loginctl_users`](#-systemd--loginctl_users)
135135
* [`dropin_files`](#-systemd--dropin_files)
136+
* [`manage_units`](#-systemd--manage_units)
137+
* [`manage_dropins`](#-systemd--manage_dropins)
136138
* [`manage_all_network_files`](#-systemd--manage_all_network_files)
137139
* [`network_path`](#-systemd--network_path)
138140
* [`manage_accounting`](#-systemd--manage_accounting)
@@ -511,7 +513,23 @@ Default value: `{}`
511513

512514
Data type: `Hash`
513515

514-
Configure dropin files via hiera with factory pattern
516+
Configure dropin files via hiera and `systemd::dropin_file` with factory pattern
517+
518+
Default value: `{}`
519+
520+
##### <a name="-systemd--manage_units"></a>`manage_units`
521+
522+
Data type: `Hash[String[1], Hash[String[1], Any]]`
523+
524+
Configure units via hiera and `systemd::manage_unit` with factory pattern
525+
526+
Default value: `{}`
527+
528+
##### <a name="-systemd--manage_dropins"></a>`manage_dropins`
529+
530+
Data type: `Hash[String[1], Hash[String[1], Any]]`
531+
532+
Configure dropin files via hiera and `systemd::manage_dropin` with factory pattern
515533

516534
Default value: `{}`
517535

manifests/init.pp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@
149149
# `loginctl_user`.
150150
#
151151
# @param dropin_files
152-
# Configure dropin files via hiera with factory pattern
152+
# Configure dropin files via hiera and `systemd::dropin_file` with factory pattern
153+
#
154+
# @param manage_units
155+
# Configure units via hiera and `systemd::manage_unit` with factory pattern
156+
#
157+
# @param manage_dropins
158+
# Configure dropin files via hiera and `systemd::manage_dropin` with factory pattern
153159
#
154160
# @param manage_all_network_files
155161
#
@@ -234,6 +240,8 @@
234240
Stdlib::Absolutepath $network_path = '/etc/systemd/network',
235241
Hash $loginctl_users = {},
236242
Hash $dropin_files = {},
243+
Hash[String[1], Hash[String[1], Any]] $manage_units = {},
244+
Hash[String[1], Hash[String[1], Any]] $manage_dropins = {},
237245
Hash $udev_rules = {},
238246
Boolean $manage_coredump = false,
239247
Systemd::CoredumpSettings $coredump_settings = {},
@@ -332,4 +340,16 @@
332340
* => $resource,
333341
}
334342
}
343+
344+
$manage_units.each |$name, $resource| {
345+
systemd::manage_unit { $name:
346+
* => $resource,
347+
}
348+
}
349+
350+
$manage_dropins.each |$name, $resource| {
351+
systemd::manage_dropin { $name:
352+
* => $resource,
353+
}
354+
}
335355
}

spec/classes/init_spec.rb

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,62 @@
709709
it { is_expected.to contain_systemd__dropin_file('my-foo.conf').with_content('[Service]\nReadWritePaths=/') }
710710
end
711711

712+
context 'when passing manage_units' do
713+
let(:params) do
714+
{
715+
manage_units: {
716+
'special.service' => {
717+
'ensure' => 'present',
718+
'unit_entry' => { 'Description' => 'My Special Unit' },
719+
'service_entry' => { 'TimeoutStartSec' => '100h' },
720+
},
721+
},
722+
}
723+
end
724+
725+
it {
726+
is_expected.to contain_systemd__manage_unit('special.service').
727+
with_ensure('present').
728+
with_unit_entry({ 'Description' => 'My Special Unit' }).
729+
with_service_entry({ 'TimeoutStartSec' => '100h' })
730+
}
731+
end
732+
733+
context 'when passing manage_dropins' do
734+
let(:params) do
735+
{
736+
manage_dropins: {
737+
'foo.conf' => {
738+
'unit' => 'special.slice',
739+
'slice_entry' => { 'CPUQuota' => '999%' },
740+
},
741+
'bar.conf' => {
742+
'unit' => 'special.timer',
743+
'timer_entry' => { 'OnCalendar' => ['', 'Daily'] },
744+
},
745+
746+
},
747+
}
748+
end
749+
750+
it {
751+
is_expected.to contain_systemd__manage_dropin('foo.conf').
752+
with_unit('special.slice').
753+
with_slice_entry({ 'CPUQuota' => '999%' })
754+
}
755+
756+
it {
757+
is_expected.to contain_systemd__manage_dropin('bar.conf').
758+
with_unit('special.timer').
759+
with_timer_entry({ 'OnCalendar' => ['', 'Daily'] })
760+
}
761+
end
762+
712763
context 'with managed networkd directory' do
713764
let :params do
714765
{
715766
manage_networkd: true,
716-
manage_all_network_files: true
767+
manage_all_network_files: true,
717768
}
718769
end
719770

0 commit comments

Comments
 (0)