Installing packages across multiple hosts with CFEngine

Posted by Steve on Wed 17 May 2006 at 14:31

We've described setting up a small network of hosts managed by CFEngine previously, but once installed what do you do with it? Well one common job for automating is to ensure that you have particular packages installed upon all your clients. With CFEngine this is simple.

If you're already using CFEngine you should be familiar with copying files from your central server to your client systems. What we're going to do to manage packages is to copy two files to each client:

Install these into your preferred directory, such as /etc/cfengine with something like this in your cfagent.conf:


copy::
 /var/lib/cfengine2/masterfiles/inputs/etc/cfengine/autoapt.cfg 
    dest=/etc/cfengine/autoapt.cfg 
    mode=644 owner=root group=root type=checksum define=autoapt

 /var/lib/cfengine2/masterfiles/inputs/etc/cfengine/autoapt.pl  
    dest=/etc/cfengine/autoapt.pl 
    mode=755 owner=root group=root type=checksum define=autoapt

Note: These lines are invalid. CFEngine doesn't like lines to be broken up like this. I've only done so to avoid wrapping issues.

Notice that we define a class once the copy has completed with the "define=autoapt" piece at the end of the line.

The class definition can now be used in a shellcommands section:

shellcommands:
  autoapt::
        "/etc/cfengine/autoapt.pl"

The result of this is that if the autoapt.cfg or autoapt.pl scripts have changed they will be copied to the client(s) and the newly installed autoapt.pl script will be executed.

autoapt.pl will read the configuration file /etc/cfengine/autoapt.cfg which we also copied, and process the file to choose which packages should be installed on each client node. The configuration file looks like this:

#
# This is the configuration file for the module:autoapt cfengine that
# installs/upgrades packages automatically.
#
# The format of non-comment lines is:
#
# name: space separated list of packages
#
# Name is either the hostname of a machine, or '*' to match any host.
# 

*: deborphan less vim sudo integrit syslog-ng
desk1: emacs21

In this example the packages less, vim, sudo, and deborphan will be installed upon all managed hosts - and the machine with hostname desk1 will have emacs21 installed upon it.

The autoapt files were originally taken from this site and updated to conform to the documentation. You can download both from here:


This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2006 Steve - please ask for permission to republish or translate.