Passing host variable to iPXE menu
-
Hi All
I have a custom Fog iPXE menu entry to launch a CentOS 7 install with a kickstart file.
The parameters section of the entry looks like this:
initrd nfs://nfsserver/path/to/image/x86_64/initrd.img chain nfs://nfsserver/path/to/image/x86_64/vmlinuz initrd=initrd.img ramdisk_size=32000 dns=dnsserver ksdevice=link ip=::::myhostname::dhcp ks=nfs://nfsserver/path/to/kickstart/centos_7_kickstart.ks boot || goto MENU
This works great, I can launch from the iPXE menu and the CentOS Anaconda installer starts.
“myhostname” in…
ip=::::myhostname::dhcp
…is the host name that is passed to the CentOS Anaconda installer.
Is there a way to pass the Host Name attribute of a registered FOG host (or any FOG attribute for that matter) to this menu.
I guess I’m wondering if it’s possible to do something like:
ip=::::${foghost}::dhcp
The goal is to be able to launch the installer and have it configure the host name based on what has been configured in Fog. A bonus would be a custom task I can launch from the Fog Web Gui.
There are other ways I can assign a hostname when bootstrapping a host (DHCP “host-name” option, a script in the kickstart script etc.) but I’m interested to know if this is achievable through Fog.
Many thanks in advance for any assistance you can provide.
David. -
I’m not aware that any internal values are available in the iPXE menu, but that would be an interesting feature request.
I could see value in having the potential to expose:
hostname
imagename
primaryuser
othertag1
othertag2In the iPXE boot menu. In my limited knowledge it might be pretty easy to do. @Developers opinion??
-
I think I have a hack a solution for you. Its pretty easy.
What version of FOG are you using?
-
@george1421 OK if you are using FOG 1.4.4 and are comfortable editing a file in the fog server’s code you can do the following.
Edit this file with your favorite linux file editor:
/var/www/html/fog/lib/fog/bootmenu.class.php
Jump to line 191 and insert the following code:
$this->_Host = $Host;
Jump to line 194 and insert the following code:
sprintf('set targetname %s', $this->_Host->get(name)),
Your patched code should look like this:
Save your edits and then key in the following into your browser
http://<fog_server_ip>/fog/service/ipxe/boot.php?mac=<mac_address_of_registered_host>
replacing<fog_server_ip>
with the real IP address of your fog server and<mac_address_of_registered_host>
with a mac address of a known host. If you get a white page with no text then you did something wrong. If you get a bunch of text and at the top there is#!ipxe set targetname <name_of_host> set fog-ip
Then the edit was successful. At this point you can use
${targetname}
in your custom ipxe menu as the representation of the imaging target’s host name as defined in FOG. -
Hi George, thank you for the quick response and looking into this for me, its much appreciated! I’m on Version 1.3.0, I’m hoping that’s close enough for your solution to work. I’ll give it a try hopefully later today.
-
Your solution worked perfectly, thank you so much, George!
The next thing I need to look at doing is a new task type so I can kick off this kickstart install through the Fog web-GUI. I’ve installed the Task Type Management plugin but not sure what to enter in the fields. I’ve had a search but can’t find any documentation on this plugin. Would you be able to point me in the right direction? My menu name is “:CentOS_7_4_vm” so I assume that needs to go in one of the fields. Let me know if you would prefer I start a new post.
Thanks again
-
@dcldn Just so I’m clear, You want to… from inside fog launch a task that will instruct the client to install centos? Or do you want to pick that from the iPXE boot menu?
-
@george1421 If its the former take a look at this post: https://forums.fogproject.org/topic/10933/fog-upgrade-to-1-5-broke-pxe-installation/7
-
@dcldn said in Passing host variable to iPXE menu:
Your solution worked perfectly, thank you so much, George!
The next time I chat with the developers, I’ll ask about making this a “feature” instead of a “hack”. If it is promoted to a feature it will be in the next release (1.5.0 stable [probably]) They won’t back port solutions normally.
-
I want to click a host (or group of hosts), click the Basic Tasks menu -> Advanced tasks and choose a “Deploy CentOS” task from there which starts the kickstart installation I’ve configured in the iPXE menu. It already works fine from the iPXE menu itself.
-
@dcldn yeah, then look at the link I provided. You will need to do some programming to complete that plugin. It is only a framework. It just so happens that the OP of that thread is doing something similar to what you need. Should there be better FOG documentation, simply yes. If you are willing to contribute, please do once you get it figured out.
-
@george1421 said in Passing host variable to iPXE menu:
@dcldn said in Passing host variable to iPXE menu:
Your solution worked perfectly, thank you so much, George!
The next time I chat with the developers, I’ll ask about making this a “feature” instead of a “hack”. If it is promoted to a feature it will be in the next release (1.5.0 stable [probably]) They won’t back port solutions normally.
I suspect there are people handing off to a different provisioning solution to handle hostname config etc. for nix hosts. It’s awesome being able to do this through Fog now, particularly in my environment where I have workstations dual booting Windows and Linux.
-
@dcldn Really the FOG Client for linux should do the same thing, if you image your systems like the windows folks do (create a golden image and then clone from that). Then the fog client will rename the system and install any snapins that you might want. But if you have a working solution run with it until you run into a show stopper. Then realize there are other ways to go about things too.
-
@dcldn The FOG Client works on Linux: https://wiki.fogproject.org/wiki/index.php?title=FOG_Client
-
@george1421 said in Passing host variable to iPXE menu:
The next time I chat with the developers, I’ll ask about making this a “feature” instead of a “hack”.
AFAIK the hack is not needed at all if DHCP is properly propagating the hostname to the client within the DHCP answers as iPXE already has config setting
hostname
. So you should be able to just use${hostname}
(also see here). -
@sebastian-roth I don’t think this is possible here. I think we have the chicken and egg situation here. dhcp knows about the computer’s name because the client tells it during dhcp negotiations. In this case, the client is a new born and doesn’t know enough to tell the dhcp server its name. To get it to work correctly the OP may have to setup dhcp reservations to inform the dhcp server what the client associated with mac address xxxx is.
-
@george1421 said in Passing host variable to iPXE menu:
@dcldn Really the FOG Client for linux should do the same thing, if you image your systems like the windows folks do (create a golden image and then clone from that). Then the fog client will rename the system and install any snapins that you might want. But if you have a working solution run with it until you run into a show stopper. Then realize there are other ways to go about things too.
We currently provision our Linux boxes by bootstrapping with PXE/Kickstart which then hands off to Puppet to do the rest. I like this solution as we’re able to make incremental changes to the workstation estate through Puppet and we know that when we add a new box to the network it will end up with the same state. With that said, I can definitely see the benefits of cloning and it may be something we investigate in the future. We deploy Windows with FOG in the traditional way and it works great, multi-casting for example is a fantastic feature.
-
@george1421 said in Passing host variable to iPXE menu:
@sebastian-roth I don’t think this is possible here. I think we have the chicken and egg situation here. dhcp knows about the computer’s name because the client tells it during dhcp negotiations. In this case, the client is a new born and doesn’t know enough to tell the dhcp server its name. To get it to work correctly the OP may have to setup dhcp reservations to inform the dhcp server what the client associated with mac address xxxx is.
Exactly this. We should used to furnish boxes with the hostname through DHCP (using option 012) but it requires manually configuring reservations.