summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-03 17:22:13 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-03 18:19:26 +0100
commit5a71c9c5083c0a30102485f09f2f55c65d988ebf (patch)
tree71f27643650dd214c051706f79ca42b27bfb5498
parentNetwork rewrites. (diff)
downloadnetworking-5a71c9c5083c0a30102485f09f2f55c65d988ebf.tar.gz
networking-5a71c9c5083c0a30102485f09f2f55c65d988ebf.tar.xz
networking
-rw-r--r--manifests/init.pp20
-rw-r--r--manifests/networkd.pp21
-rw-r--r--manifests/networkd_instance.pp21
-rw-r--r--templates/unit_file.epp7
4 files changed, 43 insertions, 26 deletions
diff --git a/manifests/init.pp b/manifests/init.pp
index bd1fda8..7dc2450 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -1,18 +1,16 @@
class networking (
- String $addr4,
- String $gw4, # TODO default this to first address in subnet
+ Optional[Enum['systemd']] $provider = undef,
+ Hash[String,Hash] $items = {},
) {
# TODO choose a sensible provider here
- networking::networkd { '20-puppet':
- network => {
- 'Address' => $addr4,
- 'Gateway' => $gw4,
- 'IPv6AcceptRA' => 1,
- },
- notify_ => true,
- manage_directory => true,
+ case $provider {
+ 'systemd', undef: {
+ include ::networking::networkd
+ create_resources(networking::networkd_instance, $items)
+ }
+ default: {
+ }
}
-
}
diff --git a/manifests/networkd.pp b/manifests/networkd.pp
index 4376a29..dec2e33 100644
--- a/manifests/networkd.pp
+++ b/manifests/networkd.pp
@@ -1,14 +1,9 @@
-define networking::networkd (
- Hash $network,
- Optional[Hash] $match = { 'Name' => $facts['networking']['primary'] },
- String $root = '/',
- String $path = "${root}/etc/systemd/network",
- String $filename = $name,
- String $file = "${path}/${filename}.conf",
+class networking::networkd (
Boolean $notify_ = true,
Boolean $manage_directory = true,
+ String $root = '/',
+ String $path = "${root}/etc/systemd/network",
) {
-
if $manage_directory {
file { $path:
ensure => directory,
@@ -17,16 +12,12 @@ define networking::networkd (
}
}
- inifile::create_ini_settings({
- 'Match' => $match,
- 'Network' => $network,
- }, { path => $file, })
-
if $notify_ {
- Ini_Setting <| path == $file |>
- ~> exec { 'networkctl reload':
+ exec { 'reload networkd':
+ command => 'systemctl reload-or-restart systemd-networkd',
path => ['/bin', '/usr/bin',],
refreshonly => true,
}
}
}
+
diff --git a/manifests/networkd_instance.pp b/manifests/networkd_instance.pp
new file mode 100644
index 0000000..4089e75
--- /dev/null
+++ b/manifests/networkd_instance.pp
@@ -0,0 +1,21 @@
+define networking::networkd_instance (
+ Hash[String,Hash] $content,
+ Enum['present','absent'] $ensure = 'present',
+ String $path = $networking::networkd::path,
+ String $filename = $name,
+ Integer $priority = 20,
+ Enum['network', 'netdev', 'link'] $type = 'network',
+ String $real_filename = "${priority}-${filename}.${type}",
+ String $file = "${path}/${real_filename}",
+) {
+
+ include ::networking::networkd
+
+ file { $file:
+ ensure => $ensure,
+ content => epp('networking/unit_file.epp', {
+ data => $content
+ }),
+ notify => if $networking::networkd::notify_ { Exec['reload networkd'] } else { [] },
+ }
+}
diff --git a/templates/unit_file.epp b/templates/unit_file.epp
new file mode 100644
index 0000000..2cbfefb
--- /dev/null
+++ b/templates/unit_file.epp
@@ -0,0 +1,7 @@
+<%- | Hash[String,Hash] $data
+| -%>
+<%- $data.each |$key, $sub| { -%>
+[<%= $key %>]
+<%- $sub.each |$k, $v| { -%>
+<%= $k %>=<%= $v %>
+<%- }} -%>