help-cfengine
[Top][All Lists]
Advanced

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

Re: editfiles methodology question


From: Mark Burgess
Subject: Re: editfiles methodology question
Date: Sun, 06 Nov 2005 19:53:18 +0100

On Sun, 2005-11-06 at 12:55 -0500, Viraj Alankar wrote:
> Hello,
> 
> I have a certain task that I'd like to do but not sure what the best
> way to do it with cfengine. Any advice appreciated.
> 
> Let's say I want have a file /etc/httpd/conf.d/log_sql.conf that looks
> like the following on a couple of servers:
> 
> LoadModule log_sql_module modules/mod_log_sql.so
> LoadModule log_sql_mysql_module modules/mod_log_sql_mysql.so
> LogSQLLoginInfo mysql://my:address@hidden/apachelogs
> LogSQLCreateTables on
> LogSQLMassVirtualHosting On
> LogSQLTransferLogFormat AabHhMmRrSsTUuv
> LogSQLMachineID $(short_hostname)
> 
> Now short_hostname should be replaced with a variable that I define:
> 
> short_hostname = ( ExecResult(/bin/hostname -s) )

As Brendan said, you don't need to do this. Use $(host) from cfagent.

> So basically I have almost identical data in the file except for the
> last line, which is specific to each host. Right now I'm using an
> editfiles like the following:
> 
> editfiles:
>                 { /etc/httpd/conf.d/log_sql.conf
>                         Backup "off"
>                         AutoCreate
>                         DefineClasses "httpd_restart"
>                         BeginGroupIfNoLineMatching ".*LogSQLLoginInfo.*"
>                         Append "LoadModule log_sql_module
> modules/mod_log_sql.so"
>                         Append "LoadModule log_sql_mysql_module
> modules/mod_log_sql_mysql.so"
>                         Append "LogSQLLoginInfo
> mysql://my:address@hidden/apachelogs"
>                         Append "LogSQLCreateTables on"
>                         Append "LogSQLMassVirtualHosting On"
>                         Append "LogSQLTransferLogFormat AabHhMmRrSsTUuv"
>                         Append "LogSQLMachineID $(short_hostname)"
>                         EndGroup
>                 }

There is a variety of ways you could do this.

> But the problem is this does not really enforce the file always being
> the same. I want to distribute it from cfengine if those first 6 lines
> ever change. If the file isn't there I'd like it to be created and
> httpd restarted. I don't think I could do a copy: because the checksum
> will always be different with the short_hostname variable. If I do
> that and then an editfiles: afterwards, it seems I would always be
> restarting httpd.

You don't have to copy by checksum, you can copy by date (the default),
in which case there will be no problem with editing the file afterwards.
In that case you example already looks fine.

If the file contains $(macro) like instances already, you could simply
ask cfagent to expand them using "ExpandVariables". Alernatively you
could use a

 ReplaceAll "xxx" With "yyy"

Mark












reply via email to

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