PXE - howto create fog task for host delete?
Im just trying figure out how to create task-item for my PXE, which allow me to delete actual booted host from fog DB.
Fog 32 already has option for reimage from PXE and many other tasks are possible, but one I cant found on wiki or here on forum is option for delete host from DB.
Point is…we have several IT technicians around city and as web interface dont have any possibility to setup security level options for its users, which is basic thing for large installs, I trying to go with pxe way, but so far without success. Looks like this functionality isnt ment for pxe tasking as its call php which delete host from db…
Any suggestion how to make this possible from pxe?
Good, glad to be of help. I’ve implemented this as a feature into FOG 0.33b as well.
In FOG 0.32 it’s call is MYSQL_DATABASE where in FOG 0.33 it’s called DATABASE_NAME.
So, after a little delay I figure out what was wrong(bad @mysql_connect parameters and (!@mysql_select_db(DATABASE_NAME,$conn)) should by (!@mysql_select_db(MYSQL_DATABASE,$conn)) ). Even (require_once(BASEPATH . ‘/commons/init.database.php’); doesnt exist in 0.32.
And now after I choose yes for delete host I get that host out of db. NICE!
Well, thx Tom for yours great help with this and now I have exactly what I wanted for my colleagues.
That means there’s a typo in the auto.delete.php file. You may need to modify the database calls to match for your particular setup.
My stuff is all for 0.33 it’s all I’ve got to work with.
I have try yours modification, but after boot to regdel mod I choose delete host and then nothing happen, only every two sec it hop text up in screen, but host still remain in db. I didnt have to much time in work today for more testing, so I try again after weekend. But so far I got all files and their rights in places a script run fine to the point, where I can choose deletion of host, but after that no success. I will try to add debug option to the autodele bash script in /bin to see where it get stuck.
Working to add field for fog config that will auto update entry for password into the pie default file. Will post when complete or with status update.
wOw, this looks AMAZING Tom!!! I will definitely try this! This is some real user support here
The fog.auto.del script now asks you if you’re sure you want to delete the host and it also asks if you’d like to reinventory the system after the deletion.
If you say no to the Full Inventory, it asks if you want to quick inventory it. If you say no there, it just continues on and restarts the system.
It also goes around to the tables I am aware of (printerAssoc, snapinAssoc, groupMembers, inventory, and host) and removes the host if it exists there.
Alright, all completed and, from what I can tell, working great.
First things first.
[B]NOTE: If things aren’t running or giving permission denied errors try prepending with sudo[/B]
[CODE]sudo gunzip init.gz[/CODE]
Login to your FOG server so you are the root owner, or with someone with sudo privileges.
Change directory into your FOG tftpboot folder usually:
Create a backup of the current init.gz:
[CODE]cp /tftpboot/fog/images/init.gz /tftpboot/fog/images/init_orig.gz[/CODE]
Extract the init.gz file with:
Make a directory to mount the file (I usually create tmp inside the images folder.)
Mount the init file to the tmp directory.
[CODE]mount -o loop init tmp[/CODE]
Edit (use the editor you’re comfortable with) the etc/init.d/S99fog file:
Add these three lines [B]ABOVE[/B] the fi statement at the bottom of the page.
[CODE]elif [ “$mode” == “delreg”]; then
Now download the fog.auto.txt file linked to this post.
Then rename the file to fog.auto.del
Place on your FOG Server at:
Make sure the file is owned by user root and is executable with:
[CODE]chmod +x /tftpboot/fog/images/tmp/bin/fog.auto.del; chown root:root /tftpboot/fog/images/tmp/bin[/CODE]
Now you should be complete with the editing of the init.gz file. Close it out:
rm -rf /tftpboot/fog/images/tmp
gzip -9 init[/CODE]
Now you’re going to edit the pxe file with:
Add the following lines [B]ABOVE[/B] the PROMPT 0 line:
MENU PASSWD password
APPEND initrd=fog/images/init.gz root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp dns=X.X.X.X mode=delreg keymap= web=X.X.X.X/fog/ loglevel=4 consoleblank=0
MENU LABEL Quick Host Deletion
Automatically delete the host from FOG.
[B]NOTE: Don’t forget to change your dns and web fields for your particular host.[/B]
Of course change the MENU PASSWD to what yours is setup for encrypted or not.
Now copy the auto.delete.php file attached to this post to your service directory usually located at:
FOR MOST REDHAT DEFAULT HTTP
FOR MOST UBUNTU DEFAULT HTTP
Then you should be complete.
Hopefully you’ll understand why I didn’t want to get right up into it. One, I was at work, and two it’s more work than one really thinks of at the time. However, this solution should work well. I tested it on 0.33b and it works flawlessly. I can assume the same can, more or less, be said for 0.32, but I don’t have that to test on.
Hopefully I’ve helped.
Edited the auto.delete file so it now removes Module status as well.
Edited again to remove all fields with the host id.
Added control options to script. works beautifully from what I can tell, though I don’t know what kind of issues we’d run into with snapin, groups, printers etc…
Had to edit
to add the menu entry.
Created a new file:
Edited the init.gz file:
to add the mode initiliazation.
To actually perform the task and send it to the auto.delete.php
Will post the files and/or edits when I am done testing. I haven’t performed any menu entries in the fog.auto.del script, so if you choose the Deletion option, it will delete your host without your go Okay. If you add the password to the default file you’ll be fine though as I assume your techs would know what they’re about to do.
I’ve already got this working. I’ll post what I did when I test fully.
That’s good. Did my suggestions not assist you any?
[quote=“Tom Elliott, post: 16308, member: 7271”]The best option I could suggest for this is to create a new fog script within the init.gz file. Have the fog script call another php file within the service directory directing that php file to delete the host upon boot. This would be the way, if I’m understanding what you’re asking. However, the hosts are meant to be a sort of inventory status for the FOG system as well. So I don’t think you want anybody to just be deleting their systems from FOG because there’s an option to do so from the PXE menu.
Maybe refine the question a little as this one is a we bit garbled and hard to understand what it is you’re asking for.[/quote]
Well thx for your suggestion. Point is, if you are standing before broken PC, which you must reinstall…for example say with different image or rename PC, than this specific PC has allready in FOG db…what do you do? You need quickly resolve this…so I will show our technician guys, that they can simply choose delete PC option from PXE menu and then they can redeploy PC under another name with another atributes like type of image or with-out domain join…thats what I want and what will make my colleagues independent. And yes, sorry for my far from perfect english.
p.s: our PXE menus are of course secured with passwords, so only IT stuff can use them.
The best option I could suggest for this is to create a new fog script within the init.gz file. Have the fog script call another php file within the service directory directing that php file to delete the host upon boot. This would be the way, if I’m understanding what you’re asking. However, the hosts are meant to be a sort of inventory status for the FOG system as well. So I don’t think you want anybody to just be deleting their systems from FOG because there’s an option to do so from the PXE menu.
Maybe refine the question a little as this one is a we bit garbled and hard to understand what it is you’re asking for.