[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Determine file to copy based on classes
From: |
Allen Bettilyon |
Subject: |
Re: Determine file to copy based on classes |
Date: |
Mon, 28 Oct 2002 09:53:58 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 |
Kai Großjohann wrote:
Is there a way to implement something like the following algorithm in
CFengine?
/----
| repository=$CFINPUTS/../files # Repository of config files.
| file=etc/printcap # Config file to consider.
| prio="$HOST laptop desktop linux default"
|
| # Determine subset of $prio that is actually defined in $CFALLCLASSES.
| # Keep same order as in $prio.
| classes=""
| for x in $prio; do
| case :${CFALLCLASSES}: in
| :${x}:)
| classes="${x} ${classes}"
| ;;
| esac
| done
|
| # Now search for an existing file and copy the first file found.
| for c in $classes; do
| if [ -f $repository/$file/$c ]; then
| cp $repository/$file/$c /$file
| exit 0
| fi
| done
\----
What with all this automatic iteration over colon-separated lists and
so on it should be possible. But how?
The above is only meant to convey a general idea. It does not have
to be this exact logic. The issue is I want to write some files in
the repository and CFengine should automatically pick the "right"
one. And I don't want to write a file for each host. (Of course, it
would be easy to copy the file that's named like the host.) Instead,
I want to write files that are named after CFengine classes, and the
most specific file should be preferred.
kai
I'm not sure if this is what your looking for, but I do the following to
maintain my config files on a per host_class basis...
control:
web::
host_class = ( "/a/path/to/web_files/" )
dns::
host_class = ( "/a/path/to/dns_files/")
copy:
$(host_class)/etc dest=/etc
recurse=inf
Now, anything you put into $(host_class)/etc will get copied over IF it
has been modified. Thus far, this model has seemed to work well for me.
I also can specify specific files and hook shell commands to them:
copy:
$(host_class)/etc/aliases dest=/etc/aliases
define=rebuild_aliases
shellcommands:
rebuild_aliases::
"/usr/bin/newaliases"
There are a few snags that I've worked around:
1) Sometimes w1 needs a slightly different config than w2, but they're
both of host_class web:
copy:
$(host_class)/etc dest=/etc
recurse=inf
ignore=HOST_*
Now, I name my 'custom' per host files: HOST_w1_exports, HOST_w2_exports
I will need specificly list these files now, as they will not get
handled by the recursive copy:
w1::
$(host_class)/etc/HOST_w1_exports dest=/etc/exports
w2::
$(host_class)/etc/HOST_w2_exports dest=/etc/exports
This is how I've been doing it, and thus far, has proven to work nicely
for my needs.
-- Allen Bettilyon