Defined Type: interface::tagged

Defined in:
modules/interface/manifests/tagged.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • base_interface (String[1])
  • vlan_id (Network::VLANTag)
  • address (Optional[Stdlib::IP::Address::Nosubnet]) (defaults to: undef)
  • netmask (Optional[Network::Netmask]) (defaults to: undef)
  • family (Enum['inet', 'inet6']) (defaults to: 'inet')
  • method (String[1]) (defaults to: 'static')
  • up (Optional[String[1]]) (defaults to: undef)
  • down (Optional[String[1]]) (defaults to: undef)
  • remove (Boolean) (defaults to: false)


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
# File 'modules/interface/manifests/tagged.pp', line 2

define interface::tagged (
    String[1]                               $base_interface,
    Network::VLANTag                        $vlan_id,
    Optional[Stdlib::IP::Address::Nosubnet] $address = undef,
    Optional[Network::Netmask]              $netmask = undef,
    Enum['inet', 'inet6']                   $family  = 'inet',
    String[1]                               $method  = 'static',
    Optional[String[1]]                     $up      = undef,
    Optional[String[1]]                     $down    = undef,
    Boolean                                 $remove  = false,
) {
    stdlib::ensure_packages('vlan')

    $intf = "vlan${vlan_id}"

    if $address {
        $addr_cmd = "set iface[. = '${intf}']/address '${address}'"
    } else {
        $addr_cmd = ''
    }

    if $netmask {
        $netmask_cmd = "set iface[. = '${intf}']/netmask '${netmask}'"
    } else {
        $netmask_cmd = ''
    }

    if $up {
        $up_cmd = "set iface[. = '${intf}']/up '${up}'"
    } else {
        $up_cmd = ''
    }
    if $down {
        $down_cmd = "set iface[. = '${intf}']/down '${down}'"
    } else {
        $down_cmd = ''
    }

    if $remove {
        $augeas_cmd = [ "rm auto[./1 = '${intf}']",
                "rm iface[. = '${intf}']"
            ]
    } else {
        $augeas_cmd = [ "set auto[./1 = '${intf}']/1 '${intf}'",
                "set iface[. = '${intf}'] '${intf}'",
                "set iface[. = '${intf}']/family '${family}'",
                "set iface[. = '${intf}']/method '${method}'",
                $addr_cmd,
                $netmask_cmd,
                $up_cmd,
                $down_cmd,
                "set iface[. = '${intf}']/vlan-raw-device ${base_interface}",
            ].delete('')
    }

    if $remove {
        exec { "/sbin/ifdown ${intf}":
            before => Augeas[$intf],
            onlyif => "/sbin/ifquery ${intf}",
        }
    }

    # Use augeas
    augeas { $intf:
        incl    => '/etc/network/interfaces',
        lens    => 'Interfaces.lns',
        context => '/files/etc/network/interfaces/',
        changes => $augeas_cmd,
    }

    if !$remove {
        exec { "/sbin/ifup ${intf}":
            require     => Package['vlan'],
            subscribe   => Augeas[$intf],
            refreshonly => true,
            tag         => "interface-create-${intf}",
        }
    }
}