summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-02 04:31:50 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-02 04:44:39 +0100
commita7b0f72f220528ba4de33f52104fe674000f625a (patch)
treeeae89d0adf398eaa9e31432b85fe9d0c926bd361
downloadnetworking-a7b0f72f220528ba4de33f52104fe674000f625a.tar.gz
networking-a7b0f72f220528ba4de33f52104fe674000f625a.tar.xz
Network rewrites.
-rw-r--r--manifests/init.pp18
-rw-r--r--manifests/networkd.pp32
-rw-r--r--templates/interface.epp16
3 files changed, 66 insertions, 0 deletions
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..bd1fda8
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,18 @@
+class networking (
+ String $addr4,
+ String $gw4, # TODO default this to first address in subnet
+) {
+
+ # TODO choose a sensible provider here
+
+ networking::networkd { '20-puppet':
+ network => {
+ 'Address' => $addr4,
+ 'Gateway' => $gw4,
+ 'IPv6AcceptRA' => 1,
+ },
+ notify_ => true,
+ manage_directory => true,
+ }
+
+}
diff --git a/manifests/networkd.pp b/manifests/networkd.pp
new file mode 100644
index 0000000..4376a29
--- /dev/null
+++ b/manifests/networkd.pp
@@ -0,0 +1,32 @@
+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",
+ Boolean $notify_ = true,
+ Boolean $manage_directory = true,
+) {
+
+ if $manage_directory {
+ file { $path:
+ ensure => directory,
+ purge => true,
+ recurse => true,
+ }
+ }
+
+ inifile::create_ini_settings({
+ 'Match' => $match,
+ 'Network' => $network,
+ }, { path => $file, })
+
+ if $notify_ {
+ Ini_Setting <| path == $file |>
+ ~> exec { 'networkctl reload':
+ path => ['/bin', '/usr/bin',],
+ refreshonly => true,
+ }
+ }
+}
diff --git a/templates/interface.epp b/templates/interface.epp
new file mode 100644
index 0000000..d824f69
--- /dev/null
+++ b/templates/interface.epp
@@ -0,0 +1,16 @@
+# File managed by puppet
+auto host0
+# allow-hotplug host0
+
+iface host0 inet <%= if $addr4 { 'static' } else { 'dhcp' } %>
+<%- if $addr4 { -%>
+ address <%= $addr4 %>
+ <%- if $gw4 { -%>
+ gateway <%= $gw4 %>
+ <%- } -%>
+<%- } -%>
+
+
+iface host0 inet6 auto
+ private 0
+