From 5b88a2f75e1e7e15feb8e0c3a42a23e26ef86b32 Mon Sep 17 00:00:00 2001 From: Maciej Delmanowski Date: Wed, 22 Apr 2015 10:55:47 +0200 Subject: [PATCH] Add iPXE boot loader support --- CHANGES.rst | 2 ++ defaults/main.yml | 37 +++++++++++++++++++++ templates/etc/dhcp/dhcpd.conf.j2 | 1 + templates/etc/dhcp/ipxe.j2 | 57 ++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 templates/etc/dhcp/ipxe.j2 diff --git a/CHANGES.rst b/CHANGES.rst index ff5f8dc..5d70275 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,8 @@ v0.1.1 parsed with errors, now ``debops.dhcpd`` will detect them hand handle separately from normal networks. [drybjed] +- Add support for iPXE boot loader chain-loading and DHCP options. [drybjed] + v0.1.0 ------ diff --git a/defaults/main.yml b/defaults/main.yml index 85eda6f..79bdcff 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -148,6 +148,43 @@ dhcpd_nameservers: [] dhcpd_options: False +# ---------------- +# iPXE support +# ---------------- + +# .. envvar:: dhcpd_ipxe +# +# Add iPXE-specific options to ISC DHCP server configuration. +dhcpd_ipxe: False + + +# .. envvar:: dhcpd_ipxe_dhcp_space +# +# Add DHCP options iPXE namespace in ``dhcpd.conf`` required to support +# iPXE-specific DHCP options in the DHCP server configuration. +dhcpd_ipxe_dhcp_space: True + + +# .. envvar:: dhcpd_ipxe_chain_filename +# +# Initial file sent to hosts which requested a PXE boot, used to chain-load +# iPXE boot loader. +dhcpd_ipxe_chain_filename: 'undionly.kpxe' + + +# .. envvar:: dhcpd_ipxe_filename +# +# File sent to hosts booted with iPXE, by default load the standard menu file. +dhcpd_ipxe_filename: 'menu.ipxe' + + +# .. envvar:: dhcpd_ipxe_options +# +# Additional DHCP options in a YAML text block format, added in the iPXE +# section of the configuration. +dhcpd_ipxe_options: '' + + # ---------------------------------------- # ISC DHCP Server configuration scopes # ---------------------------------------- diff --git a/templates/etc/dhcp/dhcpd.conf.j2 b/templates/etc/dhcp/dhcpd.conf.j2 index 8228928..4890737 100644 --- a/templates/etc/dhcp/dhcpd.conf.j2 +++ b/templates/etc/dhcp/dhcpd.conf.j2 @@ -27,6 +27,7 @@ log-facility {{ dhcpd_log_facility }}; {{ dhcpd_options }} {% endif %} +{% include 'ipxe.j2' %} {% if dhcpd_keys is defined and dhcpd_keys %} {% for key in dhcpd_keys %} {{ print.key(key) }} diff --git a/templates/etc/dhcp/ipxe.j2 b/templates/etc/dhcp/ipxe.j2 new file mode 100644 index 0000000..19e2221 --- /dev/null +++ b/templates/etc/dhcp/ipxe.j2 @@ -0,0 +1,57 @@ +{% if dhcpd_ipxe is defined and dhcpd_ipxe %} +{% if dhcpd_ipxe_dhcp_space is defined and dhcpd_ipxe_dhcp_space %} +# DHCP options configuration for iPXE +option space ipxe; +option ipxe-encap-opts code 175 = encapsulate ipxe; +option ipxe.priority code 1 = signed integer 8; +option ipxe.keep-san code 8 = unsigned integer 8; +option ipxe.skip-san-boot code 9 = unsigned integer 8; +option ipxe.syslogs code 85 = string; +option ipxe.cert code 91 = string; +option ipxe.privkey code 92 = string; +option ipxe.crosscert code 93 = string; +option ipxe.no-pxedhcp code 176 = unsigned integer 8; +option ipxe.bus-id code 177 = string; +option ipxe.bios-drive code 189 = unsigned integer 8; +option ipxe.username code 190 = string; +option ipxe.password code 191 = string; +option ipxe.reverse-username code 192 = string; +option ipxe.reverse-password code 193 = string; +option ipxe.version code 235 = string; +option iscsi-initiator-iqn code 203 = string; +# Feature indicators +option ipxe.pxeext code 16 = unsigned integer 8; +option ipxe.iscsi code 17 = unsigned integer 8; +option ipxe.aoe code 18 = unsigned integer 8; +option ipxe.http code 19 = unsigned integer 8; +option ipxe.https code 20 = unsigned integer 8; +option ipxe.tftp code 21 = unsigned integer 8; +option ipxe.ftp code 22 = unsigned integer 8; +option ipxe.dns code 23 = unsigned integer 8; +option ipxe.bzimage code 24 = unsigned integer 8; +option ipxe.multiboot code 25 = unsigned integer 8; +option ipxe.slam code 26 = unsigned integer 8; +option ipxe.srp code 27 = unsigned integer 8; +option ipxe.nbi code 32 = unsigned integer 8; +option ipxe.pxe code 33 = unsigned integer 8; +option ipxe.elf code 34 = unsigned integer 8; +option ipxe.comboot code 35 = unsigned integer 8; +option ipxe.efi code 36 = unsigned integer 8; +option ipxe.fcoe code 37 = unsigned integer 8; +option ipxe.vlan code 38 = unsigned integer 8; +option ipxe.menu code 39 = unsigned integer 8; +option ipxe.sdi code 40 = unsigned integer 8; +option ipxe.nfs code 41 = unsigned integer 8; + +{% endif %} +# iPXE chain-loading configuration +if exists user-class and option user-class = "iPXE" { + filename "{{ dhcpd_ipxe_filename }}"; +{% if dhcpd_ipxe_options is defined and dhcpd_ipxe_options %} +{{ dhcpd_ipxe_options | indent(8, true) }} +{% endif %} +} else { + filename "{{ dhcpd_ipxe_chain_filename }}"; +} + +{% endif %}