summaryrefslogtreecommitdiff
path: root/manifests/util/enable_networkd.pp
blob: 40cb3d9a334b2541c839f6c50d9cf6ad2e046488 (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
36
37
38
39
define nspawn::util::enable_networkd (
  String $template_name = $name,
  String $template_dir = $nspawn::template_dir,
  String $root = "${template_dir}/${template_name}",
) {

  networking::networkd_instance { "Initial networking on ${template_name}":
    priority => 99,
    filename => 'puppet-initial',
    path     => "${root}/${networking::networkd::path}",
    content  => {
      'Match'   => {
        'Name' => 'host0',
      },
      'Network' => {
        'DHCP'         => 'ipv4',
        'IPv6AcceptRA' => 1,
      },
    },
  }

  $running = $facts['machined-info'][$template_name] != undef 
         and $facts['machined-info'][$template_name]['State'] == 'running' 

  $cmd = if $running {
    [ 'systemctl', '-M', $template_name, 'enable', 'systemd-networkd' ]
  } else {
    [ 'systemd-nspawn', '-M', $template_name, '--quiet',
      'systemctl', 'enable', 'systemd-networkd' ]
  }

  exec { "Enable systemd-networkd on ${template_name}":
    command => $cmd,
    path    => [ '/bin', '/usr/bin', ],
    # among others
    creates => "${root}/etc/systemd/system/multi-user.target.wants/systemd-networkd.service",
  }

}