From a5ed20b2aadc9359ca3add08cd7ddfdcab039f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 6 Nov 2022 16:11:43 +0100 Subject: Allow for lists in unit files. --- functions/repack.pp | 7 +++++++ manifests/networkd.pp | 1 + manifests/networkd_instance.pp | 6 +++--- templates/unit_file.epp | 5 +++-- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 functions/repack.pp 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 %> <%- } -%> -<%- }} -%> +<%- }}} -%> -- cgit v1.2.3