Puppet Class: netplan

Defined in:
manifests/init.pp

Summary

manages and applies netplan configuration

Overview

Parameters:

  • ethernets (Optional[Hash]) (defaults to: undef)

    hash with ethernet configuration (see ethernets.pp)

  • vlans (Optional[Hash]) (defaults to: undef)

    hash with vlan configuration (see vlans.pp)

  • wifis (Optional[Hash]) (defaults to: undef)

    hash with wifi configuration (see wifis.pp)

  • bridges (Optional[Hash]) (defaults to: undef)

    hash with bridges configuration (see bridges.pp)

  • bonds (Optional[Hash]) (defaults to: undef)

    hash with bonds configuration (see bonds.pp)

  • config_file (Stdlib::Absolutepath) (defaults to: '/etc/netplan/01-netcfg.yaml')

    absolute path to netplan config file

  • renderer (String) (defaults to: 'networkd')

    network renderer - can be one of 'networkd' and 'NetworkManager'

  • version (Integer) (defaults to: 2)

    netplan config file version

  • netplan_apply (Boolean) (defaults to: true)

    whether or not to apply the changes



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
99
100
101
102
103
104
105
106
107
108
# File 'manifests/init.pp', line 24

class netplan (
  Optional[Hash]       $ethernets = undef,
  Optional[Hash]       $vlans = undef,
  Optional[Hash]       $wifis = undef,
  Optional[Hash]       $bridges = undef,
  Optional[Hash]       $bonds = undef,
  Stdlib::Absolutepath $config_file = '/etc/netplan/01-netcfg.yaml',
  String               $renderer = 'networkd',
  Integer              $version = 2,
  Boolean              $netplan_apply = true,

  ){

  $notify = $netplan_apply ? {
    true    => Exec['netplan_apply'],
    default => undef,
  }

  exec { 'netplan_apply':
    command     => 'netplan apply',
    logoutput   => 'on_failure',
    refreshonly => true,
  }

  concat { $netplan::config_file:
    ensure => present,
    notify => $notify,
  }

  $headertmp = epp("${module_name}/header.epp", {
    'version'   => $version,
    'renderer'  => $renderer,
  })

  concat::fragment { 'header':
    target  => $netplan::config_file,
    content => $headertmp,
    order   => '01',
  }

  if $ethernets {
    concat::fragment { 'ethernets_header':
      target  => $netplan::config_file,
      content => "  ethernets:\n",
      order   => '10',
    }
    create_resources(netplan::ethernets, $ethernets)
  }

  if $vlans {
    concat::fragment { 'vlans_header':
      target  => $netplan::config_file,
      content => "  vlans:\n",
      order   => '20',
    }
    create_resources(netplan::vlans, $vlans)
  }

  if $wifis {
    concat::fragment { 'wifis_header':
      target  => $netplan::config_file,
      content => "  wifis:\n",
      order   => '30',
    }
    create_resources(netplan::wifis, $wifis)
  }

  if $bridges {
    concat::fragment { 'bridges_header':
      target  => $netplan::config_file,
      content => "  bridges:\n",
      order   => '40',
    }
    create_resources(netplan::bridges, $bridges)
  }

  if $bonds {
    concat::fragment { 'bonds_header':
      target  => $netplan::config_file,
      content => "  bonds:\n",
      order   => '50',
    }
    create_resources(netplan::bonds, $bonds)
  }
}