define nspawn::util::enable_networkd ( String $machine = $name, String $machine_path = "/var/lib/machines/${machine}", ) { # TODO only do this if the directory is empty networking::networkd { "Initial networking on ${machine}": filename => '20-puppet-initial', match => { 'Name' => 'host0', }, root => $machine_path, network => { 'DHCP' => 'ipv4', 'IPv6AcceptRA' => 1, }, notify_ => false, manage_directory => false, } $running = $facts['machined-info'][$machine] != Undef or $facts['machined-info'][$machine]['State'] == 'running' $cmd = if $running { [ 'systemctl', '-M', $machine, 'enable', 'systemd-networkd' ] } else { [ 'systemd-nspawn', '-M', $machine, '--quiet', 'systemctl', 'enable', 'systemd-networkd' ] } exec { "Enable systemd-networkd on ${machine}": command => $cmd, path => [ '/bin', '/usr/bin', ], # among others creates => "${machine_path}/etc/systemd/system/multi-user.target.wants/systemd-networkd.service", } }