Defined Type: interface::tagged

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

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • base_interface (Any)
  • vlan_id (Any)
  • address (Any) (defaults to: undef)
  • netmask (Any) (defaults to: undef)
  • family (Any) (defaults to: 'inet')
  • method (Any) (defaults to: 'static')
  • up (Any) (defaults to: undef)
  • down (Any) (defaults to: undef)
  • remove (Any) (defaults to: undef)
  • legacy_vlan_naming (Any) (defaults to: true)


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

define interface::tagged($base_interface, $vlan_id, $address=undef, $netmask=undef, $family='inet', $method='static', $up=undef, $down=undef, $remove=undef, $legacy_vlan_naming=true) {
    ensure_packages('vlan')

    if $legacy_vlan_naming {
        $intf = "${base_interface}.${vlan_id}"
        $vlan_raw_device_cmd = ''
    } else {
        $intf = "vlan${vlan_id}"
        $vlan_raw_device_cmd = "set iface[. = '${intf}']/vlan-raw-device ${base_interface}"
    }

    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 == true {
        $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,
                $vlan_raw_device_cmd,
            ].delete('')
    }

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

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

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