Puppet Class: install_server::dhcp_server

Defined in:
modules/install_server/manifests/dhcp_server.pp

Overview

Parameters:

  • http_server_ip (Stdlib::IP::Address::V4)
  • ensure_service (Stdlib::Ensure::Service) (defaults to: 'running')
  • mgmt_networks (Hash[String, Array[Stdlib::IP::Address]]) (defaults to: {})
  • datacenters_dhcp_config (Hash[Wmflib::Sites, Install_server::Datacenter_dhcp::Config]) (defaults to: {})


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
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
# File 'modules/install_server/manifests/dhcp_server.pp', line 5

class install_server::dhcp_server (
    Stdlib::IP::Address::V4                  $http_server_ip,
    Stdlib::Ensure::Service                  $ensure_service = 'running',
    Hash[String, Array[Stdlib::IP::Address]] $mgmt_networks  = {},
    Hash[Wmflib::Sites, Install_server::Datacenter_dhcp::Config] $datacenters_dhcp_config = {},
){

    ensure_packages(['isc-dhcp-server'])

    file { '/etc/dhcp':
        ensure => directory,
        mode   => '0444',
    }

    file { '/etc/dhcp/dhcpd.conf':
        ensure  => file,
        mode    => '0444',
        content => template('install_server/dhcp/dhcpd.conf.erb'),
        notify  => Service['isc-dhcp-server'],
    }

    # This is the general path of proxies for the automation include system.
    wmflib::dir::mkdir_p('/etc/dhcp/automation/proxies', {'purge' => true, 'recurse' => true})

    # Files with the entries managed by the automation Cookbooks (reimage) that generates
    # DHCP snippets based on DHCP Option 82 for physical hosts and MAC address based snippets
    # for Ganeti VMs.
    # Those two files are included in the main dhcpd.conf script and Puppet should not manage
    # their content, just create them if not present and fix their permissions.
    # Their content is generated by the dhcpincludes script.
    file { ['/etc/dhcp/automation/proxies/ttyS0-115200.conf',
            '/etc/dhcp/automation/proxies/ttyS1-115200.conf']:
        ensure  => file,
        mode    => '0644',
        owner   => 'root',
        group   => 'root',
        require => Package['isc-dhcp-server'],
    }

    # Those directories will be populated by the automation via cookbook with DHCP snippets
    file { ['/etc/dhcp/automation/ttyS0-115200/',
            '/etc/dhcp/automation/ttyS1-115200/']:
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    # Generate include proxies for each management network for automation.
    file { '/etc/dhcp/automation.conf':
      ensure  => file,
      owner   => 'root',
      group   => 'root',
      mode    => '0444',
      content => template('install_server/automation.conf.erb'),
      notify  => Service['isc-dhcp-server'],
    }

    $mgmt_networks.keys.each | $netname | {
      file { "/etc/dhcp/automation/proxies/mgmt-${netname}.conf":
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0444'
      }

      # Those directories will be populated by the automation via cookbook with DHCP snippets
      file { "/etc/dhcp/automation/mgmt-${netname}/":
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
      }
    }

    # DHCP configuration include compiler
    file { '/usr/local/sbin/dhcpincludes':
      ensure => present,
      owner  => 'root',
      group  => 'root',
      mode   => '0555',
      source => 'puppet:///modules/install_server/dhcpincludes.py'
    }

    # Configuration file for DHCP configuration include compiler
    # depends on $mgmt_networks variable above.
    file { '/etc/dhcp/dhcpincludes.yaml':
      ensure  => present,
      owner   => 'root',
      group   => 'root',
      mode    => '0444',
      content => template('install_server/dhcpincludes.yaml.erb')
    }

    file_line { 'dhcpd_interfaces':
        ensure  => present,
        path    => '/etc/default/isc-dhcp-server',
        line    => "INTERFACESv4=\"${facts['interface_primary']}\"  # Managed by puppet",
        match   => "INTERFACESv4=\"\"",
        require => Package['isc-dhcp-server'],
        notify  => Service['isc-dhcp-server'],
    }

    service { 'isc-dhcp-server':
        ensure    => $ensure_service,
        require   => Package['isc-dhcp-server'],
        subscribe => File['/etc/dhcp'],
    }
}