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

  • purge_config (Boolean) (defaults to: true)

    whether or not to purge the netplan directory

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


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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'manifests/init.pp', line 26

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

  file { '/etc/netplan':
    ensure => directory,
  }

  if $purge_config {
    File['/etc/netplan'] {
      purge   => true,
      recurse => true,
      force   => true,
    }
  }

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

  exec { 'netplan_apply':
    command     => '/usr/sbin/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 { 'netplan_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)
  }

  if $tunnels {
    concat::fragment { 'tunnels_header':
      target  => $netplan::config_file,
      content => "  tunnels:\n",
      order   => '60',
    }
    create_resources(netplan::tunnels, $tunnels)
  }
}