summaryrefslogtreecommitdiff
path: root/manifests/networkd_instance.pp
blob: 8e732a2c2428fb3b21fab11e9c314450f0b8ba9a (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# @summary A single systemd-networkd configuration
#
# @example A simple instanciation
#   networking::networkd_instance { 'br0':
#     type          => 'network',
#     content       => {
#       'Match'     => {
#         'Name'    => 'br0',
#       },
#       'Network'   => {
#         'Address' => [
#           '10.0.0.1/24',
#           '10.0.0.2/24',
#         ],
#       },
#     }
#  }
#
# @example The generated content form the above example
#   [Match]
#   Name=br0
#
#   [Network]
#   Address=10.0.0.1/24
#   Address=10.0.0.2/24
#
# @see systemd.network(5)
#   For valid options in network files.
# @see systemd.netdev(5)
#   For valid options in netdev files.
# @see systemd.link(5)
#   For valid options in link files.
#
# @param content
#   Complete content which will be used to generate the unit file.
#   Each top level key is a section, while each sub key is a direct
#   option name. If the value of an option is a list, then multiple
#   instances of that option will be created. If an inline list is
#   required then the strings must be joined beforehand.
#
#   If multiple instances of a section is required, then a list of
#   hashes can instead be given as the top level value.
#
#   TODO reword the above text
# @param ensure
# @param path
#   Path to base directory in which unit files will be placed.
# @param filename
#   Part of the local filename. Will be used to create human readable
#   unit file names.
# @param priority
#   Relative priority when loading files.
# @param type
#   If it's a network, netdev, or link file.
# @param real_filename
#   The final (local) filename. usefull when you *really* need to set a
#   specific filename.
# @param file
#   Absolute path to generated file, usefull you ***REALLY*** need to
#   change a specific file.
# @param mode
#   Passed along to the generated file. Networkd requires that files
#   containing secrets are non-world readable.
define networking::networkd_instance (
  Hash[String,Variant[Hash,Array[Hash]]] $content,
  Enum['present','absent'] $ensure = 'present',
  String $path = $networking::networkd::path,
  String $filename = $name,
  Integer[0, 99] $priority = 20,
  Enum['network', 'netdev', 'link'] $type = 'network',
  String $real_filename = "${sprintf('%02d', priority)}-${filename}.${type}",
  String $file = "${path}/${real_filename}",
  Optional[String] $mode = undef,
) {
  file { $file:
    ensure  => $ensure,
    owner   => 'systemd-network',
    mode    => $mode,
    content => epp("${module_name}/unit_file.epp", {
        # Keys are unit file sections
        # Values are list of section content, so
        # {
        #   'Section' => [
        #     {
        #       'key': 'value',
        #       'mvalued': ['v1', 'v2'],
        #     }
        #   ]
        # }
        # [Section]
        # key=value
        # mvalued=v1
        # mvalued=v2
        data => networking::repack($content),
    }),
    notify  => if $networking::networkd::notify_ { Exec['reload networkd'] } else { [] },
  }
}