Cfengine 2 for Debian and Ubuntu

Cfengine is a declarative system configuration tool. This helps apply standards to system configuration. The configuration files specify the desired configuration and the engine applies these specifications to the system.  It is useful to:

  • Distribute configuration files;
  • Install standard packages (including on Debian and Ubuntu with code provided here);
  • Cleanup old files; and
  • Ensure certain programs are/are not running.

This documentation applies to Cfengine version 2. Version 3 has made significant changes to the scripting structure but maintains the capability to run the version 2 format files.

The configuration is done with text files which are distributed from one or more configuration masters. The configuration files on the master server should be stored in a version control system such as CVS, Subversion, GIT.

An alternative tool is puppet.  Reliable scripted file editing in either tool is difficult to do correctly.  I maintain the files on the server and let Cfengine push out changes as required.

Required Files

There are a few files required to configure Cfengine. These are:

  • cfserver.conf – Configures the server.
  • update.conf – Simple definitions to update the configuration.
  • cfagent.conf – The major configuration file.
  • cfrun.hosts – A list of hosts running cfengine.

Configuration Overview

The configuration item reads as follows:

        definition sequence or
        action sequence....

Suggested Configuration Structure

After a few tries, I have found the following structure enables management of the configuration by area of concern. The configuration is done in package groups such as debian, main, site, ldap, monitor, and root.

The main cfagent.conf file consists only of imports of cfagent.defs, and the definition files for package groups (, etc). The definition file for a package group should always conditionally import cfagent.defs.

The actions for a group have a default extension of .actions. If there are multiple action definition files for different packages, then the extension reflects the target of the file.

I arrange the files for Cfengine as follows:

  • inputs – configuration files for Cfengine. They belong in /etc/cfengine.
  • group/package/… – other files are arranged by package with general grouping. If there is only one package in the group, the package sub-directory may be omitted.  Use additional sub-directories to simplify file management as required.  A package directory may include scripts that will be copied to binary directories.
  • user/… – files that belong in the user’s directory. Arranged in target-related sub-directories as required.
  • os/package/… – O/S specific binaries by not distributed as packages by package. These may also be copied or installed from a binary server.  I haven’t used this structure extensively.

For a package such as nut (Network UPS Tool) the file are distributed as follows:

  • inputs/ – variable definitions for the monitoring packages.
  • inputs/ – actions required to configure NUT (ups).
  • monitor/ups/* – configuration files for NUT (ups monitoring).  Host-specific files have the hostname added as an additional extension. Host group-specific file may have a host group extension if required.

Debian and Ubuntu

Most of the systems I manage with Cfengine are have Debian based operating systems. This includes Ubuntu distributions. Cfengine provides some support for package management. It provides limited support for version number comparison, which can be used to determine which packages need installation.

The Debian apt tool requires a special setup to prevent interaction with the user during installation. This will force defaults to be used on installation when available. Some packages may require pre-seeding or post-installation manual intervention to enable Debian to complete the installation.

The following /etc/cfengine/ file provides the appropriate setup for package installation.:

# - Cfengine wrapper for apt-get install


if [ $# -gt 0 ]; then
    /usr/bin/logger -p local0.notice "$0: $*"
    /usr/bin/apt-get -y -q $*


Before Cfengine can reliably install packages, the file must be installed. This can be done with this copy statement:

        $(MasterFiles)/debian/sbin r=1
                mode=755  owner=root  group=root

The following definition segment from cfengine.defs will configure Cfengine to use the above script for installing and removing packages.

        DefaultPkgMgr      = ( dpkg )
        DPKGInstallCommand = ( "/usr/local/sbin/ install %s" )
        DPKGRemoveCommand  = ( "/usr/local/sbin/ remove %s" )

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Cookie Consent with Real Cookie Banner