Skip to content

Instantly share code, notes, and snippets.

@anthonysomerset
Created September 29, 2022 07:28
Show Gist options
  • Save anthonysomerset/b83f5f8b732f4a4102c333d100337f90 to your computer and use it in GitHub Desktop.
Save anthonysomerset/b83f5f8b732f4a4102c333d100337f90 to your computer and use it in GitHub Desktop.
Preseed default iPXE - AUTOINSTALL
#!gpxe
<%#
kind: iPXE
name: Preseed default iPXE - AUTOINSTALL
model: ProvisioningTemplate
oses:
- Ubuntu
test_on:
- ubuntu4dhcp
description: |
The template to render iPXE installation script for preseed based distributions
The output is deployed on the host's subnet TFTP proxy.
See https://ipxe.org/scripting for more details
-%>
<%
iface = @host.provision_interface
subnet4 = iface.subnet
subnet6 = iface.subnet6
ip = iface.ip
mask = subnet4.mask
gw = subnet4.gateway
dns = subnet4.dns_servers.first
if subnet4 && !subnet4.dhcp_boot_mode?
ipconfig = "ip=#{ip}::#{gw}:#{mask}::::#{dns}"
elsif subnet6 && !subnet6.dhcp_boot_mode?
ipconfig = "ip=#{ip}::#{gw}:#{mask}::::#{dns}"
else
ipconfig = 'ip=dhcp'
end
image_path = @preseed_path.sub(/\/?$/, '.iso')
-%>
echo Trying to ping Gateway: ${netX/gateway}
ping --count 1 ${netX/gateway} || echo Ping to Gateway failed or ping command not available.
echo Trying to ping DNS: ${netX/dns}
ping --count 1 ${netX/dns} || echo Ping to DNS failed or ping command not available.
<% boot_files_uris = @host.operatingsystem.boot_files_uri(medium_provider) -%>
<% kernel = boot_files_uris[0] -%>
<% initrd = boot_files_uris[1] -%>
kernel <%= kernel %> initrd=initrd.img <%= ipconfig %> url=http://<%= @preseed_server %><%= image_path %> autoinstall ds=nocloud-net;s=http://<%= foreman_request_addr %>/userdata/ root=/dev/ram0 ramdisk_size=1500000 fsck.mode=skip rw auto
initrd <%= initrd %>
imgstat
sleep 2
boot
@swatkiev
Copy link

swatkiev commented Oct 7, 2022

Thank you @anthonysomerset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment