Playing with YUM API

I was migrating from one server to another and because I love python, I really try to involve it into each and every script I’m writing.
So I saved all of my installed packages in a text file called installed.txt , and using the yum python API, I managed to install all the needed packages as easy as this:

import yum
import os

f = open('./installed.txt','r')
yb = yum.YumBase()
yb.conf.assumeyes = True

for line in f.readlines() :
if yb.rpmdb.searchNevra(name=line.strip()):
print('this package is not installed {0}'.format(line))

you could do a good packaging deal with these API’s , although using Puppet or Chef would make it much more solid than this approach , but with a small amount of servers
this could be a time saver 🙂

References :

  1. No comments yet.

  1. No trackbacks yet.