summaryrefslogtreecommitdiff
path: root/modules/nspawn/manifests/util/enable_networkd.pp
blob: 2b532b9d465d7f05a7c324fb3792c85aacfc4e0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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",
  }

}