help-cfengine
[Top][All Lists]
Advanced

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

RE: Editing Files In Particular Format


From: Wheeler, John
Subject: RE: Editing Files In Particular Format
Date: Mon, 20 Oct 2003 09:37:37 -0500

Not sure how regimented you are in keeping your source files with the
information that you have below, but I do a similar thing by replacing
seed values in the file with ReplaceAll

with a file like

> oxrs.epp.server.dbpool.driver=org.postgresql.Driver
> oxrs.epp.server.dbpool.user=cbbrowne
> oxrs.epp.server.dbpool.password=@DBPOOLPASSWD@
> oxrs.epp.server.dbpool.url=jdbc:postgresql://localhost:5432/cbbrowne-
> oxrsdb
> oxrs.epp.server.dbpool.min=1
> oxrs.epp.server.dbpool.max=10
> oxrs.epp.server.dbpool.timeout=5
> oxrs.epp.server.dbpool.uses=-1

So in the control section I define a replacement value depending on
environment

control:
        ...
        staging::
                dbpool_password = ( changeme )

        qa::
                dbpool_password = ( changemetoo )

        dev::
                dbpool_password = ( whocares )

        production::
                dbpool_password = ( doublesecretprobation )


editfiles:
        { /etc/blah/myseedfile
                ReplaceAll @DBPOOLPASSWD@ "${dbpool_password}

        }

Of course this requires that you modify a seeded file with tokens that
you know you are going to replace. You also could just redefine what you
call a token as long as its unique. For example I think you could say:


(control section stays the same)

editfiles:
        {/etc/blah/mynonseededfile
                ReplaceAll      (oxrs\.epp\.server\.dbpool\.password)=*
"\1${dbpool_password}"
        }

two thing: first I've never tried the Regex above so you may have to
fiddle with it ( the \1 references the match in parenthesis). Second,
the part in parenthesis may require some escaping (note the periods). 


> -----Original Message-----
> From: Christopher Browne [mailto:cbbrowne@acm.org]
> Sent: Friday, October 17, 2003 8:41 PM
> To: help-cfengine@gnu.org
> Subject: Editing Files In Particular Format
> 
> They look like the following:
> 
> oxrs.epp.server.dbpool.driver=org.postgresql.Driver
> oxrs.epp.server.dbpool.user=cbbrowne
> oxrs.epp.server.dbpool.password=nottoosecret
> oxrs.epp.server.dbpool.url=jdbc:postgresql://localhost:5432/cbbrowne-
> oxrsdb
> oxrs.epp.server.dbpool.min=1
> oxrs.epp.server.dbpool.max=10
> oxrs.epp.server.dbpool.timeout=5
> oxrs.epp.server.dbpool.uses=-1
> 
> What I would _like_ to do is to have a series of "editing assertions"
> that would look something like the following:
> 
> DBPASSWORD = ( abc123 )  # in control section
> DBUSER = ( cbbrowne )
> editfiles:
> { /opt/app/oxrs.properties:
>   ModifyJavaEnvar (oxrs.epp.server.dbpool.password,$(DBPASSWORD))
>   ModifyJavaEnvar (oxrs.epp.server.dbpool.user,$(DBUSER))
>   # And a bunch more lines to update a whole host of properties
> }
> 
> The notion being that this would change the third line to have a new
> password value.  And a --dry-run would report that it was going to
> change the line to that.
> 
> The nearest that I _seem_ to be able to get is to try to:
>  a) Construct a DeleteLinesMatching request with a pretty hideous
>     regex, and
>  b) Have an AppendIfNoSuchLine with the "new value."
> 
> This is really quite NOT nice.
> 
> I could always write a program in some other language that would do
> the work for me.  I don't _like_ that because it throws away the
> benefits of the way cfengine can do 'dry runs' and report on what
> configuration it changes.
> 
> Another possibility would be to put the file editing into one file,
> and write a script (Perl?  Python?  Common Lisp?  N'import quoi?) that
> does the gory transformations that turns 'structured' updates looking
> like
>   ModifyJavaEnvar (propertyname,newvalue)
> into the gory regular expressions.
> 
> Has anyone tried doing this?  Any suggestions?
> --
> select 'cbbrowne' || '@' || 'acm.org';
> http://www3.sympatico.ca/cbbrowne/rdbms.html
> "If I  could find  a way to  get [Saddam  Hussein] out of  there, even
> putting a  contract out on him,  if the CIA  still did that sort  of a
> thing, assuming it ever did, I would be for it."  -- Richard M. Nixon
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-cfengine





reply via email to

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