summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifests/init.pp8
-rw-r--r--manifests/networkd.pp30
-rw-r--r--manifests/networkd_instance.pp71
3 files changed, 104 insertions, 5 deletions
diff --git a/manifests/init.pp b/manifests/init.pp
index 790c8c0..7c22df3 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -1,3 +1,11 @@
+# @summary Configures networking for the system
+#
+# @param provider
+# What service should be used to manage the networks.
+# Available types will depend on the system.
+# @param items
+# Hash which will be passed to `create_resource` with the
+# `networking::instance` suitable for the given provider.
class networking (
Optional[Enum['systemd']] $provider = undef,
Hash[String,Hash] $items = {},
diff --git a/manifests/networkd.pp b/manifests/networkd.pp
index e7db086..74d653f 100644
--- a/manifests/networkd.pp
+++ b/manifests/networkd.pp
@@ -1,3 +1,31 @@
+# @summary Systemd Networkd network provider
+#
+# Networkd is rather nice to work with, since it relies heavily on different files.
+#
+# @see systemd-networkd(8)
+# An introduction to how networkd works.
+#
+# @param notify_
+# Should the network daemon be reloaded when things changes. This is
+# most likely a transient setting as part of the development, since
+# currently things can self-destruct if not carefull.
+# @param manage_directory
+# If enabled, then the directory mentioned by `path` will both be
+# created, and purged by this module.
+#
+# TODO this should be split into two:
+# - Manage directory existance
+# - Purge directory
+# @param path
+# Directory in which network and netdev files will be placed.
+#
+# The following directories are the default search paths for Networkd,
+# so it's recommended to chose one of them:
+#
+# - `/usr/lib/systemd/network`
+# - `/usr/local/lib/systemd/network`
+# - `/run/systemd/network`
+# - `/etc/systemd/network`
class networking::networkd (
Boolean $notify_ = true,
Boolean $manage_directory = true,
@@ -11,7 +39,7 @@ class networking::networkd (
}
}
- # Force a full restort of systemd networkd to reload all configuration.
+ # Force a full restart of systemd networkd to reload all configuration.
# The alternative is to first run `networkctl reload` which reloads
# network files, followed by a `networkctl reconfigure <iface>`.
#
diff --git a/manifests/networkd_instance.pp b/manifests/networkd_instance.pp
index cbad0a2..8e732a2 100644
--- a/manifests/networkd_instance.pp
+++ b/manifests/networkd_instance.pp
@@ -1,11 +1,74 @@
+# @summary A single systemd-networkd configuration
+#
+# @example A simple instanciation
+# networking::networkd_instance { 'br0':
+# type => 'network',
+# content => {
+# 'Match' => {
+# 'Name' => 'br0',
+# },
+# 'Network' => {
+# 'Address' => [
+# '10.0.0.1/24',
+# '10.0.0.2/24',
+# ],
+# },
+# }
+# }
+#
+# @example The generated content form the above example
+# [Match]
+# Name=br0
+#
+# [Network]
+# Address=10.0.0.1/24
+# Address=10.0.0.2/24
+#
+# @see systemd.network(5)
+# For valid options in network files.
+# @see systemd.netdev(5)
+# For valid options in netdev files.
+# @see systemd.link(5)
+# For valid options in link files.
+#
+# @param content
+# Complete content which will be used to generate the unit file.
+# Each top level key is a section, while each sub key is a direct
+# option name. If the value of an option is a list, then multiple
+# instances of that option will be created. If an inline list is
+# required then the strings must be joined beforehand.
+#
+# If multiple instances of a section is required, then a list of
+# hashes can instead be given as the top level value.
+#
+# TODO reword the above text
+# @param ensure
+# @param path
+# Path to base directory in which unit files will be placed.
+# @param filename
+# Part of the local filename. Will be used to create human readable
+# unit file names.
+# @param priority
+# Relative priority when loading files.
+# @param type
+# If it's a network, netdev, or link file.
+# @param real_filename
+# The final (local) filename. usefull when you *really* need to set a
+# specific filename.
+# @param file
+# Absolute path to generated file, usefull you ***REALLY*** need to
+# change a specific file.
+# @param mode
+# Passed along to the generated file. Networkd requires that files
+# containing secrets are non-world readable.
define networking::networkd_instance (
Hash[String,Variant[Hash,Array[Hash]]] $content,
Enum['present','absent'] $ensure = 'present',
String $path = $networking::networkd::path,
String $filename = $name,
- Integer $priority = 20,
+ Integer[0, 99] $priority = 20,
Enum['network', 'netdev', 'link'] $type = 'network',
- String $real_filename = "${priority}-${filename}.${type}",
+ String $real_filename = "${sprintf('%02d', priority)}-${filename}.${type}",
String $file = "${path}/${real_filename}",
Optional[String] $mode = undef,
) {
@@ -13,7 +76,7 @@ define networking::networkd_instance (
ensure => $ensure,
owner => 'systemd-network',
mode => $mode,
- content => epp('networking/unit_file.epp', {
+ content => epp("${module_name}/unit_file.epp", {
# Keys are unit file sections
# Values are list of section content, so
# {
@@ -28,7 +91,7 @@ define networking::networkd_instance (
# key=value
# mvalued=v1
# mvalued=v2
- data => networking::repack($content),
+ data => networking::repack($content),
}),
notify => if $networking::networkd::notify_ { Exec['reload networkd'] } else { [] },
}