Importing Examples

From Cfwiki

Jump to: navigation, search

Quite frequently when a configuration has grown to include multiple files, there is a need to maintain consistent configuration data between files. Importing can help reduce redundant code and simplify maintenance.

In my example, I've moved all of my common control section out to a "library" file, which I import into every file. In this fashion, I ensure that all my control settings are consistent between various configuration files, while retaining the ability to override them when needed.

The following is a sample of my /var/cfengine/inputs/lib/CommonControl.cf:

######################################################################
# lib/CommonControl.cf

######################################################################
# classes
#
# Here we define the class that says we've loaded this library.
# Similar to define's in C headers to prevent circular imports.
# Works the same here.

classes:

       any::

               DefinedCommonControl = ( any )


######################################################################
# control section
# 
# Define common global cfengine attributes for all configurations.
# Very run of the mill stuff, but needs to be the same everywhere.

control:

       Access = ( root )

       sysadm = ( root@localhost )
       smtpserver = ( 127.0.0.1 )

       domain     = ( adamsinfoserv.com )
       timezone   = ( CST )

       IfElapsed   = ( 350 )
       ExpireAfter = ( 60 )

       OutputPrefix = ( "$(host)" )
       workdir = ( /var/cfengine )

       ChecksumPurge = ( on )
       ChecksumUpdates = ( on )

       EditFileSize = ( 50000 )

       actionsequence = ( checktimezone.CommonControl )

In order to have other configuration files inherit the control settings in CommonControl.cf, I add the following code to the beginning of each configuration before any other lines:

######################################################################
# OneOfMyConfigurationFiles.cf

######################################################################
# standard import

import:

        !DefinedCommonControl::

                /var/cfengine/inputs/lib/CommonControl.cf


######################################################################
# control section
# Necessary for defining the local actionsequence.

control:

    any::

        actionsequence = ( checktimezones )

        # Local override of a setting from CommonControl.cf
        # In this case, say I'll edit a rather large file later.

        EditFileSize = ( 99999 )

Note that the example code contained a parameter that overrides a setting inherited from CommonControl.cf, ensuring that we can change any control settings needed for local customization.

Note to Editor: Yes, I really use StudlyCaps for my configuration file names.

-- RussellAdams 2004-12-01

Personal tools