On 02/17/2012 02:55 PM, Nick Anderson wrote:
> On 02/17/2012 02:37 PM, no-re...@cfengine.com wrote:
>> Forum: CFEngine Help
>> Subject: Re: Is there a way to get the current bundle name?
>> Author: neilhwatson
>> Link to topic: https://cfengine.com/forum/read.php?3,24924,24926#msg-24926
>>
>> I'm curious why you would choose a custom bundle for each host rather than 
>> passing IP parameters to a more general purpose bundle.
> 
> Well I do pass the ip paramaters to a general purpose bundle but I
> define the ip paramaters in a specific bundle. Also I'm not to CFEngine
> smart yet ;) and I haven't seen any examples of how to organize the
> policy to do something like this.

I don't understand the reasoning behind the multitude of bundles.  Is there a 
benefit that I'm not seeing?

Cfengine supports multi-dimensional arrays.  You can make the the nodename a 
component of the array name.  I'm imagining something like this:

(NOTE: this specific example is completely untested, but I do something similar 
for other aspects of my machines (NIS, DNS, CUPS).)

"netconf[host0][interfaces]" slist => { "eth0" };
"netconf[host0][eth0][DEVICE]" string  => "eth0"
"netconf[host0][eth0][BOOTPROTO]" string  => "none"
"netconf[host0][eth0][ONBOOT]" string  => "yes";
"netconf[host0][eth0][IPADDR]" string  => "192.168.35.11";
"netconf[host0][eth0][NETMASK]" string  => "255.255.255.0";

"netconf[host1][interfaces]" slist => { "eth0" , "eth1" };
"netconf[host1][eth0][DEVICE]" string  => "eth0"
"netconf[host1][eth0][BOOTPROTO]" string  => "none"
"netconf[host1][eth0][ONBOOT]" string  => "yes";
"netconf[host1][eth0][IPADDR]" string  => "192.168.35.12";
"netconf[host1][eth0][NETMASK]" string  => "255.255.255.0";
"netconf[host1][eth1][DEVICE]" string  => "eth1"
"netconf[host1][eth1][BOOTPROTO]" string  => "none"
"netconf[host1][eth1][ONBOOT]" string  => "yes";
"netconf[host1][eth1][IPADDR]" string  => "10.1.1.1";
"netconf[host1][eth1][NETMASK]" string  => "255.255.255.0";

You could then make your files promises on

"/etc/sysconfig/network-scripts/ifcfg-$(netconf[$(sys.uqhost)][interfaces])"

and pass in "$(netconf[$(sys.uqhost)][$(netconf[$(sys.uqhost)][interfaces])])" 
to your parameterized bundle.

Those should expand to (assuming your uqhost is "host0"):

"/etc/sysconfig/network-scripts/ifcfg-eth0"
and
$(netconf[host0][eth0])

And "$(netconf[host0][eth0])" will be a 1 dimensional array with the keys of 
"DEVICE","BOOTPROTO", etc.

I don't think this is an issue when using the set_variable_values bundle from 
the COPBL, but before using a variable in an edit_line promise, I suggest you 
make sure that the variable exists.  That way you don't end up with an 
unexpanded Cfengine variable name in your configuration files.  See the 
isvariable function for this purpose.  Should probably check that the 
"interfaces" slist is defined too before you use it in the files promise.  I 
suspect it might try to create a file with the unexpanded variable name in the 
file name if the variable isn't defined first.

/* Wes Hardin */
UNIX/Linux Systems Administrator, IT Engineering Support
Maxim Integrated Products | Innovation Delivered® | www.maxim-ic.com


 
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to