cobbler – automatically disable netboot after ubuntu installation

January 26, 2010

in linux

UPDATE (1/28): Michael DeHaan posted a comment that a feature like this is already built into cobbler — see his comment below. One thing to be careful of is what gets inserted when you use $kickstart_done — for Ubuntu / Debian preseeds you need to separate multiline scripts with a “\” character, otherwise later lines might get ignored. If you *just* want to replicate the $kickstart_done un-pxe function built into cobbler, add this to your preseed file:

d-i preseed/late_command string wget "http://cobbler_host/cblr/svc/op/nopxe/system/$system_name" -O /dev/null

The method I describe below accomplishes the same thing, but it’s easier to not reinvent the wheel like I did…. heh! Here’s the original post:

Cobbler (https://fedorahosted.org/cobbler/) is a very neat tool, and I’m using it for some bare-metal provisioning of Ubuntu. It’s great how you can target a particular kickstart (or preseed) file for a particular machine, and have it auto-magically install. Problem is, until you uncheck the “enable netboot” option in the system management screen in Cobbler, your target box will continually reboot into the installer and reinstall (this is assuming you have your preseed set up to be completely unattended, and your target machine set to always pxe boot). What I wanted was to be able to check the “enable netboot” option, reboot the target box and then be able to just “walk away” — when installation completes, the target box will “call back” to cobbler to tell it to uncheck the netboot option. Here’s how I did it (this is ubuntu-install-centric, but I’m sure the same can apply to other linux flavors):

First, add a “callback” url to the Cobbler web UI. This will be the way that machines will tell cobbler to uncheck the netboot box. In cobbler_web/urls.py add the line shown in the middle here:

46
47
48
    (r'^check$', check),
    (r'^unpxe/(?P<system_name>.+)$', unpxe), # ADD ME
)

Then in cobbler_web/views.py add this at the bottom:

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
 
def unpxe(request,system_name):
 
	"""
	unchecks the pxe boot box
	"""
 
	if not remote.has_item("system", system_name):
		return error_page(request,"Failure trying to access item %s, it may have been deleted." % (obj_name))
	obj_id = remote.get_item_handle( "system", system_name, token )
 
	try:
		remote.modify_item("system",obj_id,"netboot_enabled",False,token)
	except Exception, e:
		return error_page(request, str(e))                
 
	try:
		remote.save_item("system", obj_id, token, "edit")
	except Exception, e:
		return error_page(request, str(e))
 
	return HttpResponseRedirect('/cobbler_web/system/list')

Then, in your preseed / kickstart, you’ll want to have a script that grabs this url (i.e., http://username:password@cobbler_host/cobbler_web/unpxe/the_system_name) once the install is complete. Using Cobbler’s awesome templating system, you can have a reusable line in your ubuntu preseeds. Make it look like this:

d-i preseed/late_command string wget http://username:password@cobbler_host/cobbler_web/unpxe/$system_name; exit 0

Cobbler will insert the system name when the installing box requests the preseed file. Assuming the rest of your preseed defines an unattended install, when it’s done the netboot option will uncheck and the system will boot right into the new ubuntu install! Pretty cool, huh?

Cheers

{ 2 comments… read them below or add one }

Michael DeHaan January 27, 2010 at 10:47 pm

Pretty sure I implemented this years ago, and should be nicely distro agnostic.

See pxe_just_once in the settings file.

You’ll need $kickstart_done at the bottom of your preseed template so the macro expands, but it has little to do with actual kickstart.

matt January 27, 2010 at 11:52 pm

Ha! talk about reinventing the wheel… My quick doc search didn’t reveal this feature (I’ve only been playing with cobbler for about a week now). I’ll update the post to reference this built-in feature. Great work Michael, by the way. Luvin’ this cobbler stuff…

Leave a Comment

Previous post:

Next post: