3

I've been looking around, and haven't yet seen an example of anyone using logic to determine packages/package group selections for options beneath %packages. I'm trying to have kickstart install packages based on criteria discovered in %pre, for instance:

%pre
    if [ "$(/usr/sbin/dmidecode -s system-manufacturer)" = 'Dell Inc.' ]; then
        echo 'srvadmin-all'
    elif [ "$(/usr/sbin/dmidecode -s system-manufacturer)" = 'VMware, Inc.' ]; then
        echo 'open-vm-tools'
    fi
%end

I've never seen an example of conditional logic in the %packages section, but I was thinking about printing all of the output into a file that is referenced with an %include statement but I've had issues with %include under %packages since RHEL7.

I'm curious to know if there are any other methods anyone is using successfully along these lines.

Michael Moser
  • 219
  • 2
  • 4
  • 16
  • Without a config management system like Puppet, I'd take what you have out of %pre, put it in %post and change echo to yum -y install. If I did have a config management system, I'd do as generic an install as possible and move the rest of the work over to the config management system. An over-engineered solution might use the KSSENDMAC option on a PXE boot to determine the vendor and let the web server generate the package list programatically based on the mac address prefix. –  Feb 07 '18 at 19:08

1 Answers1

2

You can use kickstart's ability to include files to accomplish this. Use your %pre section to write a file containing the packages you want, and then include the file in the %packages section.

For example:

%pre --interpreter=/bin/bash
touch /tmp/packages
if [ "$(/usr/sbin/dmidecode -s system-manufacturer)" = "Dell Inc." ]; then
    echo 'srvadmin-all' >> /tmp/packages
elif [ "$(/usr/sbin/dmidecode -s system-manufacturer)" = "VMware, Inc." ]; then
    echo 'open-vm-tools' >> /tmp/packages
fi
%end

%packages
@core
@base
chrony
%include /tmp/packages
%end
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940