PXE - howto create fog task for host delete?
-
I’ve already got this working. I’ll post what I did when I test fully.
-
Had to edit
[CODE]/tftpboot/pxelinux.cfg/default[/CODE]
to add the menu entry.Created a new file:
[CODE]/var/www/fog/service/auto.delete.php[/CODE]Edited the init.gz file:
Edited File:
[CODE]/etc/init.d/S99fog[/CODE]
to add the mode initiliazation.
Created File:
[CODE]/bin/fog.auto.del[/CODE]
To actually perform the task and send it to the auto.delete.phpWill 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.
-
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…
-
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]EXAMPLE:
[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:
[CODE]cd /tftpboot/fog/images[/CODE]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:
[CODE]gunzip init.gz[/CODE]Make a directory to mount the file (I usually create tmp inside the images folder.)
[CODE]mkdir tmp[/CODE]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:
[CODE]vi tmp/etc/init.d/S99fog[/CODE]Add these three lines [B]ABOVE[/B] the fi statement at the bottom of the page.
[CODE]elif [ “$mode” == “delreg”]; then
run=“/bin/fog.auto.del”;
after=$afterActionTerm;[/CODE]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:
[CODE]/tftpboot/fog/images/tmp/bin[/CODE]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:
[CODE]cd /tftpboot/fog/images
umount /tftpboot/fog/images/tmp
rm -rf /tftpboot/fog/images/tmp
gzip -9 init[/CODE]Now you’re going to edit the pxe file with:
[CODE]cd /tftpboot/pxelinux.cfg
vi default[/CODE]Add the following lines [B]ABOVE[/B] the PROMPT 0 line:
[CODE]LABEL fog.del
MENU PASSWD password
KERNEL fog/kernel/bzImage
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
TEXT HELP
Automatically delete the host from FOG.
ENDTEXT[/CODE][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
[CODE]/var/www/html/fog/service[/CODE]
or:
FOR MOST UBUNTU DEFAULT HTTP
[CODE]/var/www/fog/service[/CODE]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.
[url=“/_imported_xf_attachments/0/402_fog.auto.txt?:”]fog.auto.txt[/url][url=“/_imported_xf_attachments/0/406_auto.delete.php?:”]auto.delete.php[/url]
-
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.
-
wOw, this looks AMAZING Tom!!! I will definitely try this! This is some real user support here
-
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.
-
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.
-
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.
-
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.
-
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.