[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Cfengine packages WAS Re: Other possible cfengine weak areas?
From: |
John Sechrest |
Subject: |
Cfengine packages WAS Re: Other possible cfengine weak areas? |
Date: |
Mon, 02 Feb 2004 07:55:58 -0800 |
David Douthitt <ssrat@mailbag.com> writes:
% > > I do this already. Set up a class (such as "web" for web
% > > servers) and put each host into each class. Then, as I use
% > > apt-rpm, I do the following:
% > > web::
% > > "apt-get -qyy <rpms....>"
...
% I was thinking I should write a script to handle some of this (in Ruby
% of course) and send it a list of RPMs with a leading + or - and let
% it remove and add as appropriate. Thus you could specify what a
% particular server looks like, and replicate it elsewhere.
In order to solve a problem with the MLN setup that we are working
on, we in fact wrote a program to do this in perl.
It works like a charm.
I do not remove packages yet, thinking that disk space is cheap
and system failure is expensive. But we do turn off services.
Here is a perl program that looks at two files, one is a role to host
mapping and the other is a role to package mapping.
I have other programs that do each of these seperately.
-
to call the module, I use:
control:
hosts2role = ( /var/mln/hosts2role )
packagebyrole = ( /var/mln/packagebyrole )
# This finds all of the roles that this machine are bound to.
gotinit = ( PrepModule(module:getpkgbyrolefromhost,"${hosts2role}
${packageby
role} ${host}") )
--
PrepModule is a new feature in the 2.1.2a6 version of cfengine.
It was needed as a way to call the module in the right way.
-- cut here----
#!/usr/bin/perl
#
# 2004/01/24
# John Sechrest/ Kyrre Begnum
# sechrest@peak.org / kyrre.begnum@iu.hio.no
#
# module:getpkgbyrolefromhost
#
# Given the file named: $file - /var/mln/hosts2role
# and a file named: $rolefile - /var/mln/packagebyrole
# and a hostname called $host
# then find all of the roles that the host has
# and then print them out with a + in front
# And print out a list of all the packagestohave as a variable
# This is a merger of the idea of getrolebyhost and get packagebyrole.
# Given
# The hosts2role is of the form:
# ID machine host role featurelist
# as a tab seperated file
# Like:
# 3 rex host1 web
# 4 rex host2 dns
# the packagebyrole file is of the form:
# ID role package featurelist
# as a tab seperated file
# Like:
# 3 web apache
# 4 dns bind9
$debug=0;
# Get the filename and hostname out of the parameters
# They should be in ArgV
# assume that $ARGV[0] = filename;
# and that $ARGV[1] = hostname;
if ($debug) {print "#Argv: $#ARGV\n";}
if ($#ARGV != 2) {
print "MODULE ERROR: Arguments to getrolebyhost must be: hosts2role
packageb
yrole hostname\n";
exit(1);
}
$filename=$ARGV[0];
$rolename=$ARGV[1];
$hostname=$ARGV[2];
#Open the file
if ($debug) {print "Filename: $filename\n";}
if ($debug) {print "rolename: $rolename\n";}
if ($debug) {print "hostname: $hostname\n";}
$i = 0;
open (PACKAGELIST , "< $rolename") or die"Module ERROR: Could Not open
$rolename
\n" ;
while ( $line=<PACKAGELIST> ){
if ($debug) {print "package line: $line\n";}
$line=~s/#.*$//; # Delete any comments
if ($debug) {print "package line w/o #: $line\n";}
chop ($line);
($id,$role,$package,$featurelist) = split /\t+/, $line;
if ($debug) {print "packagerole: $role\n";}
if ($debug) {print "package: $package\n";}
$rolelist[$i][0]=$role;
$rolelist[$i][1]=$package;
$rolelist[$i][2]=$featurelist;
$i=$i+1;
}
$rolearraysize= $i-1;
$modulelist ="";
close (PACKAGELIST);
open (MYFILE , "< $filename") or die"Module ERROR: Could Not open $filename\n"
;
# For each line in the file
while ( $line=<MYFILE> ){
if ($debug) {print "line: $line\n";}
$line=~s/#.*$//; # Delete any comments
if ($debug) {print "line w/o #: $line\n";}
($id,$machine,$host,$role,$featurelist) = split /\t+/, $line;
if ($debug) {print "host: $host\n";}
if ($debug) {print "hostname: $hostname\n";}
# if it is for host $host, then get the role
# write out +role
if ( $host eq $hostname ){
print "+$role\n";
$i=0;
while ($i < $rolearraysize ){
if ($rolelist[$i][0] eq $role )
{ $modulelist = $modulelist . " " . $rolelist[$i][1];
if ($debug) {print "modulelist: $modulelist\n";}
if ($debug) {print "rolelist: $rolelist[$i][1]\n";}
}
$i=$i+1;
}
}
if ($debug) {print "host: $host -> role printend and packages assigned
\n";
}
# end
}
if ( $modulelist ne "" ) {
print "=packagestohave = ( $modulelist ) \n";
}
# close file
close MYFILE;
-----
John Sechrest . Helping people use
. computers and the Internet
. more effectively
.
. Internet: sechrest@peak.org
.
. http://www.peak.org/~sechrest
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Cfengine packages WAS Re: Other possible cfengine weak areas?,
John Sechrest <=