Skip to content

Commit

Permalink
Lazily load tftp directories
Browse files Browse the repository at this point in the history
This change makes tftp directories lazy. It does that by making the
parameters undef by default and determine them if tftp is actually
included.

The main motivation is that f849d12
changed the tftp module. Prior to it, the logic was duplicated. With
that change, it became dynamic which also made it a hard dependency.
Technically it already was since it's always been listed in
metadata.json. However, it functioned without it if tftp was false. With
this change it really becomes optional.
  • Loading branch information
ekohl committed May 27, 2021
1 parent d3156b3 commit 37cdeca
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@
Boolean $tftp_managed = $foreman_proxy::params::tftp_managed,
Boolean $tftp_manage_wget = $foreman_proxy::params::tftp_manage_wget,
Array[Stdlib::Absolutepath] $tftp_syslinux_filenames = $foreman_proxy::params::tftp_syslinux_filenames,
Stdlib::Absolutepath $tftp_root = $foreman_proxy::params::tftp_root,
Array[Stdlib::Absolutepath] $tftp_dirs = $foreman_proxy::params::tftp_dirs,
Optional[Stdlib::Absolutepath] $tftp_root = $foreman_proxy::params::tftp_root,
Optional[Array[Stdlib::Absolutepath]] $tftp_dirs = $foreman_proxy::params::tftp_dirs,
Optional[String] $tftp_servername = $foreman_proxy::params::tftp_servername,
Boolean $tftp_replace_grub2_cfg = $foreman_proxy::params::tftp_replace_grub2_cfg,
Boolean $dhcp = $foreman_proxy::params::dhcp,
Expand Down
5 changes: 5 additions & 0 deletions manifests/module/httpboot.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
class foreman_proxy::module::httpboot (
Boolean $enabled = $foreman_proxy::httpboot,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::httpboot_listen_on,
Optional[Stdlib::Absolutepath] $root_dir = $foreman_proxy::tftp_root,
) {
if $enabled {
assert_type(NotUndef, $root_dir)
}

foreman_proxy::module { 'httpboot':
enabled => $enabled,
feature => 'HTTPBoot',
Expand Down
5 changes: 5 additions & 0 deletions manifests/module/tftp.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
class foreman_proxy::module::tftp (
Boolean $enabled = $foreman_proxy::tftp,
Foreman_proxy::ListenOn $listen_on = $foreman_proxy::tftp_listen_on,
Optional[Stdlib::Absolutepath] $tftproot = $foreman_proxy::tftp_root,
) {
if $enabled {
assert_type(NotUndef, $tftproot)
}

foreman_proxy::module { 'tftp':
enabled => $enabled,
listen_on => $listen_on,
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# @summary The default parameters for the foreman proxy
# @api private
class foreman_proxy::params inherits foreman_proxy::globals {
$tftp_root = lookup('tftp::root')
$lower_fqdn = downcase($facts['networking']['fqdn'])

case $facts['os']['family'] {
Expand Down Expand Up @@ -227,7 +226,8 @@
$tftp_listen_on = 'https'
$tftp_managed = true
$tftp_manage_wget = true
$tftp_dirs = ["${tftp_root}/pxelinux.cfg","${tftp_root}/grub","${tftp_root}/grub2","${tftp_root}/boot","${tftp_root}/ztp.cfg","${tftp_root}/poap.cfg"]
$tftp_root = lookup('tftp::root', undef, undef, undef)
$tftp_dirs = undef
$tftp_servername = undef
$tftp_replace_grub2_cfg = false

Expand Down
4 changes: 1 addition & 3 deletions manifests/plugin/discovery/params.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Default parameters for foreman_proxy::plugin::discovery
# @api private
class foreman_proxy::plugin::discovery::params {
include foreman_proxy::params

$install_images = false
$tftp_root = $foreman_proxy::params::tftp_root
$tftp_root = lookup('tftp::root')
$source_url = 'http://downloads.theforeman.org/discovery/releases/latest/'
$image_name = 'fdi-image-latest.tar'
}
24 changes: 13 additions & 11 deletions manifests/tftp.pp
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# @summary Set up the tftp service
# @api private
class foreman_proxy::tftp (
$user = $foreman_proxy::user,
$root = $foreman_proxy::tftp_root,
$directories = $foreman_proxy::tftp_dirs,
$syslinux_filenames = $foreman_proxy::tftp_syslinux_filenames,
$manage_wget = $foreman_proxy::tftp_manage_wget,
$wget_version = $foreman_proxy::ensure_packages_version,
$tftp_replace_grub2_cfg = $foreman_proxy::tftp_replace_grub2_cfg,
String[1] $user = $foreman_proxy::user,
Optional[Stdlib::Absolutepath] $root = $foreman_proxy::tftp_root,
Optional[Array[Stdlib::Absolutepath]] $directories = $foreman_proxy::tftp_dirs,
Array[Stdlib::Absolutepath] $syslinux_filenames = $foreman_proxy::tftp_syslinux_filenames,
Boolean $manage_wget = $foreman_proxy::tftp_manage_wget,
String[1] $wget_version = $foreman_proxy::ensure_packages_version,
Boolean $tftp_replace_grub2_cfg = $foreman_proxy::tftp_replace_grub2_cfg,
) {
class { 'tftp':
root => $root,
}

file { $directories:
$dirs = pick($directories, prefix(['pxelinux.cfg','grub','grub2','boot','ztp.cfg','poap.cfg'], "${tftp::root}/"))

file { $dirs:
ensure => directory,
owner => $user,
mode => '0644',
require => Class['foreman_proxy::install', 'tftp::install'],
recurse => true,
}

file { "${root}/grub2/grub.cfg":
file { "${tftp::root}/grub2/grub.cfg":
ensure => file,
owner => $user,
mode => '0644',
Expand All @@ -31,7 +33,7 @@

$syslinux_filenames.each |$source_file| {
$filename = basename($source_file)
file {"${root}/${filename}":
file {"${tftp::root}/${filename}":
ensure => file,
owner => $user,
mode => '0644',
Expand All @@ -45,7 +47,7 @@
}

class { 'foreman_proxy::tftp::netboot':
root => $root,
root => $tftp::root,
require => File[$directories],
}
contain foreman_proxy::tftp::netboot
Expand Down
2 changes: 1 addition & 1 deletion templates/httpboot.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# configuration files deployment.
:enabled: <%= @module_enabled %>

:root_dir: <%= scope.lookupvar('foreman_proxy::tftp_root') %>
:root_dir: <%= scope.lookupvar('foreman_proxy::module::httpboot::root_dir') %>
2 changes: 1 addition & 1 deletion templates/tftp.yml.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# TFTP management
:enabled: <%= @module_enabled %>
:tftproot: <%= scope.lookupvar("foreman_proxy::tftp_root") %>
:tftproot: <%= scope.lookupvar("foreman_proxy::module::tftp::tftproot") %>
# Defines the TFTP Servername to use, overrides the name in the subnet declaration
<%= '#' if [nil, :undefined, :undef].include?(scope.lookupvar("foreman_proxy::tftp_servername")) %>:tftp_servername: <%= scope.lookupvar("foreman_proxy::tftp_servername") %>

0 comments on commit 37cdeca

Please sign in to comment.