Rice University logo
 
Top blue bar image
A place to post stuff
 

Python Yum Fun 2: Kickstart List

Need to create a Red Hat kickstart config to duplicate the installed packages off an existing system? Want to do this without having to create a giant file listing each RPM by hand?

Here’s a python script that will pull your installed packages list and prune it down by dependencies and yum groups, and give you a (hopefully) concise list of yum groups and RPMs that will work in a kickstart config file. The only complication is that you’ll need to ensure all your yum repositories are available at kickstart time, else you may run into some RPMs that are not available.

#!/usr/bin/env python
import yum

yb = yum.YumBase()
yb.doConfigSetup()
yb.doTsSetup()
yb.doRpmDBSetup()
    
# Grab Installed Package List (ipl)
ipl=set([pkg[0] for pkg in yb.rpmdb.pkglist])
grppkgs = set([])
# Grab Group List (gl)
gl=yb.doGroupLists()
# First index of gl is Installed Group List (igl)
igl=gl[0]

# Make sure we still are accounting for Core (sometimes packages get removed)
gotcore = False
for grp in igl:
    if grp.groupid == 'core': gotcore = True

if not gotcore:
    for grp in gl[1]:
        if grp.groupid == 'core':
           igl.append(grp)

# Find leaves of dependency tree
loners = ipl.copy()
for pkg in list(loners):
    deps= yb.findDeps(yb.returnInstalledPackagesByDep(pkg)).values()[0].keys()
    for dep in [d[0] for d in deps] :
        if dep in loners:
            loners.remove(pkg)
            break

# Print a kickstartable group list first
for grp in igl:
    for pkg in grp.mandatory_packages:
        if pkg in loners:
            loners.remove(pkg)
    for pkg in grp.default_packages:
        if pkg in loners:
            loners.remove(pkg)
    print '@'+grp.groupid

# Print rpms not pruned already
for pkg in loners:
   print pkg

Tags: , , ,

Comments are closed.