[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Suggestion for future release
From: |
Mark Burgess |
Subject: |
Re: Suggestion for future release |
Date: |
Fri, 10 Mar 2006 20:35:40 +0100 |
You mean like ReadFile() ?
On Wed, 2006-03-08 at 16:47 +0000, Marco van Beek wrote:
> Hi Everyone,
>
> I have a suggestion for CFengine. It would be nice to be able to have a
> plain text config file with variables, which could be read by a client
> on a host by host, and/or class by class basis.
>
> The data would be read in by CFEngine (probably set in cfagent.conf) and
> would be available to all subsequent cf files being processed.
>
> I did something a while ago because I wanted to read the same data in
> Perl as PHP for a project I have been dabbling with.
>
> Anyway, an example config plus working Perl code is below. It would save
> me having to use complicated bash code to extract data from a plain text
> file. I have a config file per host which means I can define each boxes
> purpose outside of CFEngine, which makes it easier to maintain.
>
> Cheers,
>
> Marco
>
>
> ==============================================================
> EXAMPLE CONFIG FILE
> ==============================================================
>
> #######################################
> # Cross language config file for SSiS #
> #######################################
> # Comments are allowed #
> # White space is allowed #
> # syntax is 'key = value' #
> ###########################
>
> ...
>
> #########
> # MySQL #
> #########
>
> mysql_server = localhost
> mysql_datasource = dbi:mysql:ssis
> mysql_database = ssis
> mysql_username = ssis
> mysql_password = ssis
> mysql_palm_gluetable = PDA_Sync
> mysql_ldap_gluetable = LDAP_Sync
>
> ########
> # LDAP #
> ########
>
> ou = ou=SSiS
> dc = dc=supporting-role,dc=co,dc=uk
> ldap_bindas = uid=ssis,ou=People,dc=supporting-role,dc=co,dc=uk
> ldap_password = secret
> ldap_server = localhost
> ldap_port = 389
> ldap_version = 3
>
> ===============================================================
> PERL CODE TO EXTRACT FROM CONFIG AND DUMP INTO ARRAY
> ================================================================
> my %settings;
> open(CONFIG,"/etc/ssis-config");
> while(<CONFIG>)
> {
> chomp; # no newline
> s/#.*//; # no comments
> s/^\s+//; # no leading whitespace
> s/\s+$//; # no trailing whitespace
> next unless length; # Anything left?
> my ($var, $value) = split(/\s*=\s*/,$_, 2);
> $settings{$var} = $value;
> }
> close CONFIG;
>
> my $mysql_datasource = $settings{"mysql_datasource"};
> my $mysql_username = $settings{"mysql_username"};
> my $mysql_password = $settings{"mysql_password"};
> my $mysql_palm_gluetable = $settings{"mysql_palm_gluetable"};
> my $public_user = $settings{"public_user"};
> my $Memo_user = $settings{"Memo_user"};
> my $ToDo_user = $settings{"ToDo_user"};
> my $Address_user = $settings{"Address_user"};
> my $Datebook_user = $settings{"Datebook_user"};
> ==================================================================
>
>
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-cfengine