Puppet Class: pxe_install

Inherits:
pxe_install::params
Defined in:
manifests/init.pp

Summary

PXE Install server

Overview

Set up an PXE install server with dhcp, tftp and webserver for serving files

Examples:

include pxe_install

Parameters:

  • installserverip (String)

    The ip of the install server

  • installserver (String)

    Hostname of the install server

  • repo_server (String)

    Hostname of the server hosting the package repositories

  • repo_server_ip (String)

    IP of the server hosting the package repositories

  • repos_dir (Stdlib::Unixpath)

    Directory location of the package repositories

  • repos_url (String)

    URI where the pacjaqges can be found on the repo server

  • scriptdir (Stdlib::Unixpath)

    Directory location where to cfreate scripts and prepared files

  • scripturl (String)

    URL where to find the scripts

  • kickstart_dir (Stdlib::Unixpath)

    Directory location for the kickstart/preseed files

  • kickstart_url (String)

    Url where to download the kickstart/preseed files

  • puppetmaster (Optional[String]) (defaults to: undef)

    The hostname of the Puppet master server

  • puppetmasterip (Optional[String]) (defaults to: undef)

    The ip of the Puppet master server

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

    Hash with services to configure. Valid are dhcp and tftp. Each service is a hash of how to configure that service.

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

    Hash with all machines to get installed. Each entry i a whole description of a machine with ips, partitions and so on.

  • status_allow_from (Array) (defaults to: ['127.0.0.1'])

    Allow Apache status URLs from these ips

  • enabled (Boolean) (defaults to: true)

    Installserver is enbaled or not

  • ssl_cert (String) (defaults to: '/etc/pki/httpd/repos.example.com/repos.example.com.cer')

    Location of the SSL certificate for the webserver to use. he file has to exist on the install server.

  • ssl_key (String) (defaults to: '/etc/pki/httpd/repos.example.com/repos.example.com.key')

    Location of the SSL key for the webserver to use. he file has to exist on the install server.

  • ssl_chain (String) (defaults to: '/etc/pki/httpd/repos.example.com/fullchain.cer')

    Location of the SSL certificate chain for the webserver to use. he file has to exist on the install server.

  • ssl_certs_dir (String) (defaults to: '/etc/pki/httpd/repos.example.com/')

    Directory where all files for the cdertificates reside.

  • documentroot (String) (defaults to: '/var/www/html')

    Document root for the webserver.

  • create_aliases (Boolean) (defaults to: true)

    Create webserver aliases

  • challenge_password (Sensitive[String])

    Sensitive challenge password for auto signing cert requests.

  • add_hosts_entries (Boolean) (defaults to: false)

    Add install server and puppet server to /etc/hosts file.

  • install_curl (Boolean) (defaults to: $pxe_install::params::install_curl)

    Install curl package

  • install_unzip (Boolean) (defaults to: $pxe_install::params::install_unzip)

    Install unzip package

  • syslinux_url (Stdlib::HTTPSUrl) (defaults to: $pxe_install::params::syslinux_url)

    The url where to download the syslinux archive.

  • syslinux_name (String) (defaults to: $pxe_install::params::syslinux_name)

    Ther name of the archive.

  • syslinux_version (String) (defaults to: $pxe_install::params::syslinux_version)

    The version of the archive.

  • ipxefile (Stdlib::HTTPUrl) (defaults to: $pxe_install::params::ipxefile)

    The url to download the ipxe file.

  • mirrors (Hash) (defaults to: $pxe_install::params::mirrors)

    Hash with mirror definitions.

  • defaults (Hash) (defaults to: $pxe_install::params::defaults)

    Default values.

  • purge_apache_configs (Boolean) (defaults to: false)

    Boolean to indicate that all Apache configurations not maintained by the Apache Puppet module should be deleted.

Author:

  • Thomas Krieger



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'manifests/init.pp', line 110

class pxe_install (
  String $installserverip,
  String $installserver,
  String $repo_server,
  String $repo_server_ip,
  Stdlib::Unixpath $repos_dir,
  String $repos_url,
  Stdlib::Unixpath $scriptdir,
  String $scripturl,
  Stdlib::Unixpath $kickstart_dir,
  String $kickstart_url,
  Sensitive[String] $challenge_password,
  Optional[String] $puppetmaster          = undef,
  Optional[String] $puppetmasterip        = undef,
  Optional[Hash] $services                = undef,
  Optional[Hash] $machines                = undef,
  Array $status_allow_from                = ['127.0.0.1'],
  Boolean $enabled                        = true,
  String $ssl_cert                        = '/etc/pki/httpd/repos.example.com/repos.example.com.cer',
  String $ssl_key                         = '/etc/pki/httpd/repos.example.com/repos.example.com.key',
  String $ssl_chain                       = '/etc/pki/httpd/repos.example.com/fullchain.cer',
  String $ssl_certs_dir                   = '/etc/pki/httpd/repos.example.com/',
  String $documentroot                    = '/var/www/html',
  Boolean $create_aliases                 = true,
  Boolean $add_hosts_entries              = false,
  Stdlib::HTTPSUrl $syslinux_url          = $pxe_install::params::syslinux_url,
  String $syslinux_name                   = $pxe_install::params::syslinux_name,
  String $syslinux_version                = $pxe_install::params::syslinux_version,
  Stdlib::HTTPUrl $ipxefile               = $pxe_install::params::ipxefile,
  Boolean $install_curl                   = $pxe_install::params::install_curl,
  Boolean $install_unzip                  = $pxe_install::params::install_unzip,
  Hash $mirrors                           = $pxe_install::params::mirrors,
  Hash $defaults                          = $pxe_install::params::defaults,
  Boolean $purge_apache_configs           = false,
) inherits pxe_install::params {
  $_puppetmaster = $puppetmaster ? {
    undef   => '',
    default => $puppetmaster,
  }

  $_puppetmasterip = $puppetmasterip ? {
    undef   => '',
    default => $puppetmasterip
  }

  $_services = $services ? {
    undef   => {},
    default => $services,
  }

  $_machines = $machines ? {
    undef   => '',
    default => $machines,
  }

  pxe_install::parent_dirs { 'create script dir':
    dir_path => $scriptdir,
  }

  pxe_install::parent_dirs { 'create kickstart dirs':
    dir_path => $kickstart_dir,
  }

  pxe_install::parent_dirs { 'create document root dir':
    dir_path => $documentroot,
  }

  file { "${scriptdir}/debian-post.sh":
    ensure  => file,
    content => epp('pxe_install/scripts/debian-post.sh.epp', {
        installserver      => $installserver,
        installserverip    => $installserverip,
        puppetmaster       => $_puppetmaster,
        puppetmasterip     => $_puppetmasterip,
        kickstart_url      => $kickstart_url,
        repos_url          => $repos_url,
        scripturl          => $scripturl,
        challenge_password => $challenge_password,
        add_hosts_entries  => $add_hosts_entries,
    }),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
  }

  file { "${scriptdir}/debian-rc.local":
    ensure  => file,
    content => epp('pxe_install/scripts/debian.rc.local.epp', {}),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
  }

  file { "${scriptdir}/ubuntu-post.sh":
    ensure  => file,
    content => epp('pxe_install/scripts/ubuntu-post.sh.epp', {
        installserver      => $installserver,
        installserverip    => $installserverip,
        puppetmaster       => $_puppetmaster,
        puppetmasterip     => $_puppetmasterip,
        kickstart_url      => $kickstart_url,
        repos_url          => $repos_url,
        scripturl          => $scripturl,
        challenge_password => $challenge_password,
        add_hosts_entries  => $add_hosts_entries,
    }),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
  }

  file { "${scriptdir}/redhat-post.sh":
    ensure  => file,
    content => epp('pxe_install/scripts/redhat-post.sh.epp', {
        installserver      => $installserver,
        installserverip    => $installserverip,
        puppetmaster       => $_puppetmaster,
        puppetmasterip     => $_puppetmasterip,
        kickstart_url      => $kickstart_url,
        repos_url          => $repos_url,
        scripturl          => $scripturl,
        reposerver         => $repo_server,
        reposerverip       => $repo_server_ip,
        challenge_password => $challenge_password,
        add_hosts_entries  => $add_hosts_entries,
    }),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
  }

  file { "${scriptdir}/fedora-post.sh":
    ensure  => file,
    content => epp('pxe_install/scripts/fedora-post.sh.epp', {
        installserver      => $installserver,
        installserverip    => $installserverip,
        puppetmaster       => $_puppetmaster,
        puppetmasterip     => $_puppetmasterip,
        kickstart_url      => $kickstart_url,
        repos_url          => $repos_url,
        scripturl          => $scripturl,
        reposerver         => $repo_server,
        reposerverip       => $repo_server_ip,
        challenge_password => $challenge_password,
        add_hosts_entries  => $add_hosts_entries,
    }),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
  }

  if pxe_install::hash_key($_services, 'dhcpd') {
    $dhcpd = $_services['dhcpd']
    class { 'pxe_install::dhcp':
      dhcp => $dhcpd,
    }
  }

  if pxe_install::hash_key($_services, 'tftpd') {
    $tftpd = $_services['tftpd']
    class { 'pxe_install::tftp':
      tftp => $tftpd,
    }
  }

  if pxe_install::hash_key($_services, 'samba') {
    $samba = $_services['samba']
    class { 'samba':
      * => $samba,
    }
  }

  class { 'pxe_install::apache':
    kickstart_dir     => $kickstart_dir,
    kickstart_url     => $kickstart_url,
    pub_dir           => $scriptdir,
    pub_url           => $scripturl,
    repos_dir         => $repos_dir,
    repos_url         => $repos_url,
    servername        => $repo_server,
    status_allow_from => $status_allow_from,
    ssl_cert          => $ssl_cert,
    ssl_key           => $ssl_key,
    ssl_chain         => $ssl_chain,
    ssl_certs_dir     => $ssl_certs_dir,
    documentroot      => $documentroot,
    create_aliases    => $create_aliases,
    purge_configs     => $purge_apache_configs,
  }

  $tftpboot_dir = pxe_install::hash_key($tftpd, 'directory') ? {
    true => $tftpd['directory'],
    default => '/var/lib/tftpboot',
  }

  $windows_dir = pxe_install::hash_key($tftpd, 'windows_directory') ? {
    true    => $tftpd['windows_directory'],
    default => '/windows',
  }

  $windows_config_dir = pxe_install::hash_key($tftpd, 'windows_config_directory') ? {
    true    => $tftpd['windows_config_directory'],
    default => '',
  }

  $windows_domain = pxe_install::hash_key($tftpd, 'windows_domain') ? {
    true    => $tftpd['windows_domain'],
    default => '',
  }

  pxe_install::parent_dirs { 'create tftpboot windows scripts dir':
    dir_path => "${tftpboot_dir}${windows_dir}/scripts",
  }

  pxe_install::parent_dirs { 'create tftpboot windows unattend dir':
    dir_path => "${tftpboot_dir}${windows_dir}/unattend",
  }

  pxe_install::parent_dirs { 'create tftpboot grub dir':
    dir_path => "${tftpboot_dir}/grub",
  }

  $win_locale = pxe_install::hash_key($defaults, 'win_locale') ? {
    true  => $defaults['win_locale'],
    false => 'en-US',
  }

  $win_input_locale = pxe_install::hash_key($defaults, 'win_input_locale') ? {
    true  => $defaults['win_input_locale'],
    false => 'en-US',
  }

  file { "${tftpboot_dir}${windows_dir}/scripts/install.ps1":
    ensure  => file,
    content => epp('pxe_install/windows/install.ps1.epp', {
        domain => $windows_domain,
    }),
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
  }

  file { "${tftpboot_dir}${windows_dir}/unattend/2019_bios.xml":
    ensure  => file,
    content => epp('pxe_install/windows/2019_bios.xml.epp', {
        domain           => $windows_domain,
        win_locale       => $win_locale,
        win_input_locale => $win_input_locale,
    }),
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
  }

  file { "${tftpboot_dir}${windows_dir}/unattend/2019_uefi.xml":
    ensure  => file,
    content => epp('pxe_install/windows/2019_uefi.xml.epp', {
        domain           => $windows_domain,
        win_locale       => $win_locale,
        win_input_locale => $win_input_locale,
    }),
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
  }

  ensure_resource('file', ["${tftpboot_dir}/grub"], {
      ensure       => directory,
      purge        => true,
      recurselimit => 1,
      recurse      => true,
      owner        => 'root',
      group        => 'root',
      mode         => '0755',
  })

  file { "${tftpboot_dir}/grub/grub.cfg":
    ensure => file,
    source => 'puppet:///modules/pxe_install/grub.cfg',
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
  }

  $_machines.each |$hostname, $data| {
    pxe_install::kickstart { $hostname:
      data               => $data,
      kickstart_dir      => $kickstart_dir,
      kickstart_url      => $kickstart_url,
      repos_url          => $repos_url,
      scripturl          => $scripturl,
      dhcp_entry         => pxe_install::hash_key($_services, 'dhcpd'),
      tftp_entry         => pxe_install::hash_key($_services, 'tftpd'),
      puppetmaster       => $_puppetmaster,
      challenge_password => $challenge_password,
      tftpboot_dir       => $tftpboot_dir,
      windows_dir        => $windows_dir,
      windows_config_dir => $windows_config_dir,
    }
  }
}