Passing variables in kickstart
Make a nochroot %post
snippet and move the hostname in there instead:
%post --nochroot
echo $hostname > /mnt/sysimage/home/hostname
If $hostname
variable changes, then echo the $hostname
in %pre
to temporary location, and then move the file in %post --nochroot
instead.
This is because %pre
takes place before you install, and you've got no /mnt/sysimage/home
yet. That's why you want to work your magic after the OS is installed, and since %pre
works outside of the chroot, and regular %post
inside, you must do the move in nochroot %post
.
Related videos on Youtube
ThatGuy
Updated on September 18, 2022Comments
-
ThatGuy almost 2 years
I have a kickstart file that takes a hostname in the %pre section. I cannot seem to figure out how to get it two the first. As you see it sends the server information to another device which then customizes the server based on another database. I need to figure out how to take the hostname parameter in pre however and send it to post.
%pre #!/bin/sh exec < /dev/tty6 > /dev/tty6 chvt 6 clear echo "################################" echo "# Running Pre Configuration #" echo "################################" echo -n "Give hostname: " read hostname hostname $hostname echo $hostname > /home/hostname echo $hostname > /mnt/sysimage/home/hostname exec < /dev/tty1 > /dev/tty1 chvt 1 %packages @base @core %post exec < /dev/tty6 > /dev/tty6 chvt 6 ip0=`ifconfig eth0 |grep -e addr:10.0|cut -d':' -f2|awk '{print $1}'`; ip1=`ifconfig eth1 |grep -e addr:10.0|cut -d':' -f2|awk '{print $1}'`; mac0=`ifconfig eth0 |grep HWaddr|awk '{print $5}'`; mac1=`ifconfig eth1 |grep HWaddr|awk '{print $5}'`; os=`cat /home/hostname` ; hostname=`cat /home/hostname`; service sshd start echo "$ip0^$mac0^$ip1^$mac1^$os^$hostname^none" >/dev/tcp/10.0.0.1/999 exec < /dev/tty1 > /dev/tty1 chvt 1
In the above the "hostname $hostname" does work for some O.S's but not all. I would like to make it dynamic based on the information submitted in pre but am having no luck.
-
Admin about 10 yearsNot exactly what you're looking to solve, but I avoid this route altogether by just doing it all in the post. The
kssendmac
flag to anaconda can help going this route but I simply look for MAC addresses in /sys/class/net/*/address and call a cgi for each MAC addr in the post to return all the networking/hostname configuration. -
Clément Perroud almost 10 yearsOr you could use cobbler and be done with it :)
-
ThatGuy almost 10 yearsCobbler is going to give me the same issue. Yoonix, my goal is to make it so that I do it in the prescript. I basically want the hostname asked at the start of the install. I use this then "echo "$ip0^$mac0^$ip1^$mac1^$os^$hostname^none" >/dev/tcp/10.0.0.1/999" Which is a nother server that provisions out a lot of different machine types. The reason I want to prompt in pre and use the same value in post is that means an admin inserting during "pre" can insert, then is completely done with that install. My 10.0.0.1 handels everything else later on based on the hostname and other systems.
-
-
resultsway over 8 yearsso how is the flow of anaconda ? %pre (only initrd) , installOS, %post-nochroot, %post-chroot-of-installedOS ? and $hostname is filled up by anaconda process itself ? - Thanks