07 September 2012

RPM and YUM trick: synchronize packages installed on two hosts

The question was asked in IRC today:

hello folks, is there any way to install packages from a list written by yum list installed? I've two CentOS 6.3 hosts and I like to get them with the same packages installed (also versions)

Here is a quick (and accurate) answer:

  1. Take and test backups to taste
  2. Run:
    rpm -qa --qf '%{name} \n' | sort > MANIFEST
    Note: that is a backslash n -- the html markup makes it hard to see the distinction
  3. Then copy that MANIFEST to the second unit and run:
    yum -y install `cat MANIFEST`
    Note: and here, backtick around the cat to get a sub-shell
  4. Finish by running:
    yum -y update
    on each unit

For extra credit, re-run the MANIFEST creator on each unit, and use diff to find any variances