help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use of editfile to support templated configuration files


From: Jamie Wilkinson
Subject: Re: Use of editfile to support templated configuration files
Date: Wed, 15 Dec 2004 13:18:38 +1100
User-agent: Mutt/1.5.6+20040907i

This one time, at band camp, address@hidden wrote:
>Each managed service must have several related cfengine script lines,
>which occur in various sections, such as shellcommands and processes.
>And, each stanza of script lines consists of perhaps half a dozen or
>more lines. If you want to manage several dozen services, this entails
>quite a few lines of cfengine script code. I prefer concise code, where
>possible. So, I'm working on a way to automatically generate the
>necessary cfengine script lines.

Ok, you twisted my arm; everything you wrote is pretty much the same reason
I came up with my macros.

http://anchor.net.au/~jaq/cfm4.tar.gz

The README might help you out, there's no examples, it's undocumented; but
here's a bit that might start you off:

  tomcat4.cf.in

# -*- cfengine -*- fragment for tomcat4

groups:

  tomcat4_server = ( host )

packages:

  tomcat4_server::

    tomcat4 elsedefine=tomcat4_install
    mod_jk2 elsedefine=mod_jk2_install

CF_SHELLCOMMANDS_RESTART(tomcat4)
CF_SHELLCOMMANDS_CHKCONFIG(tomcat4, 3)
CF_SHELLCOMMANDS_INSTALL(tomcat4)
CF_SHELLCOMMANDS_INSTALL(tomcat4, mod_jk2)
CF_SHELLCOMMANDS_OUTPUT

  vsftpd.cf.in

# vsftpd configuration -*- cfengine -*-

groups:

    vsftpd_server = ( host )

    vsftpd_conf_new = ( FileExists(/etc/vsftpd/vsftpd.conf) )

control:

    AllowRedefinitionOf = ( vsftpd_banner vsftpd_client_sources 
vsftpd_anonymous )

    vsftpd_anonymous = ( NO )
    vsftpd_client_sources = ( ALL )
    vsftpd_banner = ( "FTP server" )
    
    vsftpd_conf_new::

        vsftpd_conf = ( /etc/vsftpd/vsftpd.conf )

    !vsftpd_conf_new::

        vsftpd_conf = ( /etc/vsftpd.conf )

copy:

    vsftpd_server.filtergen_server::

        CF_COPY_FILE_FROM(/etc/filtergen/input.d/cf.vsftpd, $(copysrc), 0644,
            filtergen_configtest)
        CF_COPY_FILE_FROM(/etc/filtergen/output.d/cf.vsftpd, $(copysrc), 0644,
            filtergen_configtest)

editfiles:

    vsftpd_server::

        CF_EDIT_FILE($(vsftpd_conf),
            CF_EDITFILES_KEYVAL_SEP(anonymous_enable, =, ${vsftpd_anonymous})
            CF_EDITFILES_KEYVAL_SEP(ascii_upload_enable, =, YES)
            CF_EDITFILES_KEYVAL_SEP(ascii_download_enable, =, YES)
            CF_EDITFILES_KEYVAL_SEP(ftpd_banner, =, ${vsftpd_banner})
            CF_EDITFILES_KEYVAL_SEP(ls_recurse_enable, =, YES)
            CF_EDITFILES_KEYVAL_SEP(chroot_local_user, =, YES)
            CF_EDITFILES_KEYVAL_SEP(pasv_min_port, =, 30000)
            CF_EDITFILES_KEYVAL_SEP(pasv_max_port, =, 60000)
            CF_EDITFILES_KEYVAL_SHELL(local_umask, 0072),
            vsftpd_restart)
 
    vsftpd_server.redhat_es_3::

        CF_EDIT_FILE($(vsftpd_conf),
            CF_EDITFILES_KEYVAL_SEP(force_dot_files, =, YES),
            vsftpd_restart)

    vsftpd_server.vsftpd_use_localtime.redhat_es_3::

        CF_EDIT_FILE($(vsftpd_conf),
            CF_EDITFILES_KEYVAL_SEP(use_localtime, =, YES),
            vsftpd_restart)

    vsftpd_server.!redhat_es_3::

        CF_EDIT_FILE($(vsftpd_conf), <<
            DeleteLinesMatching '^force_dot_files.*'>>,
            vsftpd_restart)

CF_PROCESSES_DAEMON(vsftpd)
CF_PROCESSES_OUTPUT

CF_SHELLCOMMANDS_RESTART(vsftpd)
CF_SHELLCOMMANDS_CHKCONFIG(vsftpd, 3)
CF_SHELLCOMMANDS_OUTPUT

My repository has the following structure:

 cfagent.conf - imports only:

import:

  # global settings
  main.cf

  # services
  tomcat4.cf
  vsftpd.cf

The _APPEND macros allow you to add extra verbatim blocks of cfengine code
to those sections that have it (so far only processes and shellcommands).
It's nowhere near as flexible as I wanted it to be, but for reducing the
tedium it's been pretty useful.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]