Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to purge non-managed networkd files #209

Merged
merged 1 commit into from
Jul 27, 2021
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
14 changes: 14 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ The following parameters are available in the `systemd` class:
* [`logind_settings`](#logind_settings)
* [`loginctl_users`](#loginctl_users)
* [`dropin_files`](#dropin_files)
* [`manage_all_network_files`](#manage_all_network_files)
* [`network_path`](#network_path)
* [`manage_accounting`](#manage_accounting)
* [`accounting`](#accounting)
* [`purge_dropin_dirs`](#purge_dropin_dirs)
Expand Down Expand Up @@ -309,6 +311,18 @@ Configure dropin files via hiera with factory pattern

Default value: `{}`

##### <a name="manage_all_network_files"></a>`manage_all_network_files`

Data type: `Boolean`



##### <a name="network_path"></a>`network_path`

Data type: `Stdlib::Absolutepath`

where all networkd files are placed in

##### <a name="manage_accounting"></a>`manage_accounting`

Data type: `Boolean`
Expand Down
2 changes: 2 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ systemd::udev_timeout_signal: ~
systemd::udev_resolve_names: ~
systemd::manage_logind: false
systemd::logind_settings: {}
systemd::manage_all_network_files: false
systemd::network_path: '/etc/systemd/network'
7 changes: 7 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
#
# @param dropin_files
# Configure dropin files via hiera with factory pattern
#
# @param manage_all_network_files
#
# @param network_path
# where all networkd files are placed in
class systemd (
Hash[String,Hash[String, Any]] $service_limits,
Boolean $manage_resolved,
Expand Down Expand Up @@ -146,6 +151,8 @@
Optional[Variant[Integer,String]] $udev_timeout_signal,
Boolean $manage_logind,
Systemd::LogindSettings $logind_settings,
Boolean $manage_all_network_files,
Stdlib::Absolutepath $network_path,
Hash $loginctl_users = {},
Hash $dropin_files = {},
Hash $udev_rules = {},
Expand Down
20 changes: 16 additions & 4 deletions manifests/networkd.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# @api private
#
# This class provides an abstract way to trigger systemd-networkd
#
# @param ensure
# The state that the ``networkd`` service should be in
# @summary This class provides an abstract way to trigger systemd-networkd
#
# @param ensure The state that the ``networkd`` service should be in
# @param path path where all networkd files are placed in
# @param manage_all_network_files if enabled, all networkd files that aren't managed by puppet will be purged
class systemd::networkd (
Enum['stopped','running'] $ensure = $systemd::networkd_ensure,
Stdlib::Absolutepath $path = $systemd::network_path,
Boolean $manage_all_network_files = $systemd::manage_all_network_files,
) {
assert_private()

Expand All @@ -20,4 +22,14 @@
ensure => $ensure,
enable => $_enable_networkd,
}
# this directory is created by systemd
# we define it here to purge non-managed files
if $manage_all_network_files {
file { $path:
ensure => 'directory',
recurse => true,
purge => true,
notify => Service['systemd-networkd'],
}
}
}
13 changes: 13 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
it { is_expected.to create_service('systemd-resolved').with_enable(true) }
it { is_expected.to create_service('systemd-networkd').with_ensure('running') }
it { is_expected.to create_service('systemd-networkd').with_enable(true) }
it { is_expected.not_to contain_file('/etc/systemd/network') }
end

context 'when enabling resolved with DNS values (string)' do
Expand Down Expand Up @@ -439,6 +440,18 @@

it { is_expected.to contain_systemd__dropin_file('my-foo.conf').with_content('[Service]\nReadWritePaths=/') }
end
context 'with managed networkd directory' do
let :params do
{
manage_networkd: true,
manage_all_network_files: true
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('systemd::networkd') }
it { is_expected.to contain_file('/etc/systemd/network').with_ensure('directory') }
end
end
end
end
Expand Down