From a7b0f72f220528ba4de33f52104fe674000f625a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 2 Jan 2022 04:31:50 +0100 Subject: Network rewrites. --- manifests/init.pp | 18 ++++++++++++++++++ manifests/networkd.pp | 32 ++++++++++++++++++++++++++++++++ templates/interface.epp | 16 ++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 manifests/init.pp create mode 100644 manifests/networkd.pp create mode 100644 templates/interface.epp 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 + -- cgit v1.2.3