forked from voxpupuli/puppet-systemd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request voxpupuli#244 from traylenator/modules
Manage entries in modules-load.d directory
- Loading branch information
Showing
5 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Creates a modules-load.d drop file | ||
# | ||
# @api public | ||
# | ||
# @see modules-load.d(5) | ||
# | ||
# @param filename | ||
# The name of the modules-load.d file to create | ||
# | ||
# @param ensure | ||
# Whether to drop a file or remove it | ||
# | ||
# @param path | ||
# The path to the main systemd modules-load.d directory | ||
# | ||
# @param content | ||
# The literal content to write to the file | ||
# | ||
# * Mutually exclusive with ``$source`` | ||
# | ||
# @param source | ||
# A ``File`` resource compatible ``source`` | ||
# | ||
# * Mutually exclusive with ``$content`` | ||
# | ||
# @example load a module | ||
# systemd::modules_load{'impi.conf': | ||
# content => "ipmi\n", | ||
# } | ||
# | ||
# @example override /lib/modules-load.d/myservice.conf in /etc/modules-load.d/myservice.conf | ||
# systemd::modules_load{'myservice.conf': | ||
# content => "# Cancel system version of the file\n", | ||
# } | ||
# | ||
define systemd::modules_load ( | ||
Enum['present', 'absent', 'file'] $ensure = 'file', | ||
Systemd::Dropin $filename = $name, | ||
Stdlib::Absolutepath $path = '/etc/modules-load.d', | ||
Optional[String[1]] $content = undef, | ||
Optional[String[1]] $source = undef, | ||
) { | ||
include systemd::modules_loads | ||
|
||
$_tmp_file_ensure = $ensure ? { | ||
'present' => 'file', | ||
default => $ensure, | ||
} | ||
|
||
file { "${path}/${filename}": | ||
ensure => $_tmp_file_ensure, | ||
content => $content, | ||
source => $source, | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0444', | ||
notify => Class['systemd::modules_loads'], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Activate the modules contained in modules-loads.d | ||
# | ||
# @api private | ||
# | ||
# @see systemd-modules-load.service(8) | ||
# | ||
class systemd::modules_loads { | ||
exec { 'systemd-modules-load' : | ||
command => 'systemctl start systemd-modules-load.service', | ||
refreshonly => true, | ||
path => $facts['path'], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'systemd::modules_load' do | ||
context 'supported operating systems' do | ||
on_supported_os.each do |os, os_facts| | ||
context "on #{os}" do | ||
let(:facts) { os_facts } | ||
let(:title) { 'random_module.conf' } | ||
let(:params) { { content: 'random stuff' } } | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
it { is_expected.to contain_systemd__modules_load('random_module.conf') } | ||
|
||
it { is_expected.to contain_file('/etc/modules-load.d/random_module.conf') } | ||
|
||
it { | ||
is_expected.to contain_file('/etc/modules-load.d/random_module.conf').with | ||
|
||
{ | ||
ensure: 'file', | ||
content: 'random stuff', | ||
mode: '0444' | ||
} | ||
} | ||
|
||
it { is_expected.to contain_class('systemd::modules_loads') } | ||
it { is_expected.to contain_exec('systemd-modules-load').with_command('systemctl start systemd-modules-load.service') } | ||
|
||
context 'with a bad modules-load name' do | ||
let(:title) { 'test.badtype' } | ||
|
||
it { | ||
is_expected.to compile.and_raise_error(%r{expects a match for Systemd::Dropin}) | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |