# @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 { [] }, } }