summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-11-06 16:11:43 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-11-06 21:43:20 +0100
commita5ed20b2aadc9359ca3add08cd7ddfdcab039f34 (patch)
tree3e27ab63ececf78f79b0e5a503992eb11218677f
parentAdd puppet notice to generated sytemd files. (diff)
downloadnetworking-a5ed20b2aadc9359ca3add08cd7ddfdcab039f34.tar.gz
networking-a5ed20b2aadc9359ca3add08cd7ddfdcab039f34.tar.xz
Allow for lists in unit files.
-rw-r--r--functions/repack.pp7
-rw-r--r--manifests/networkd.pp1
-rw-r--r--manifests/networkd_instance.pp6
-rw-r--r--templates/unit_file.epp5
4 files changed, 14 insertions, 5 deletions
diff --git a/functions/repack.pp b/functions/repack.pp
new file mode 100644
index 0000000..396354c
--- /dev/null
+++ b/functions/repack.pp
@@ -0,0 +1,7 @@
+# Normalizes a hash or a list of hashes to a list of hashes
+function networking::repack(Variant[Hash, Array[Hash]] $data) >> Array[Hash] {
+ $data ? {
+ Hash => [$data],
+ _ => $data,
+ }
+}
diff --git a/manifests/networkd.pp b/manifests/networkd.pp
index ca0f5a2..5b34a32 100644
--- a/manifests/networkd.pp
+++ b/manifests/networkd.pp
@@ -11,6 +11,7 @@ class networking::networkd (
}
}
+ # Why this instead of `networkctl reload`?
if $notify_ {
exec { 'reload networkd':
command => 'systemctl reload-or-restart systemd-networkd',
diff --git a/manifests/networkd_instance.pp b/manifests/networkd_instance.pp
index 4089e75..07465b6 100644
--- a/manifests/networkd_instance.pp
+++ b/manifests/networkd_instance.pp
@@ -1,5 +1,5 @@
define networking::networkd_instance (
- Hash[String,Hash] $content,
+ Hash[String,Variant[Hash,Array[Hash]]] $content,
Enum['present','absent'] $ensure = 'present',
String $path = $networking::networkd::path,
String $filename = $name,
@@ -14,8 +14,8 @@ define networking::networkd_instance (
file { $file:
ensure => $ensure,
content => epp('networking/unit_file.epp', {
- data => $content
+ data => networking::repack($content),
}),
- notify => if $networking::networkd::notify_ { Exec['reload networkd'] } else { [] },
+ notify => if $networking::networkd::notify_ { Exec['reload networkd'] } else { [] },
}
}
diff --git a/templates/unit_file.epp b/templates/unit_file.epp
index 1482b29..6751058 100644
--- a/templates/unit_file.epp
+++ b/templates/unit_file.epp
@@ -1,8 +1,9 @@
-<%- | Hash[String,Hash] $data
+<%- | Hash[String,Array[Hash]] $data
| -%>
# File managed by PUPPET
<%- $data.each |$key, $sub| { -%>
+<%- $sub.each |$sub| { -%>
[<%= $key %>]
<%- $sub.each |$k, $v| { -%>
<%- if $v =~ Array { $v.each |$v| { -%>
@@ -10,4 +11,4 @@
<%- } } else { -%>
<%= $k %>=<%= $v %>
<%- } -%>
-<%- }} -%>
+<%- }}} -%>