-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Saturday 06 October 2007, Ryan Cross wrote:> I am trying to allow certain nodes to override variables in inherited
> classes. Here''s an example:
>
> node ''my.server.com'' inherits webserver {}
>
> node ''other.server.com'' inherits webserver { $var =
"newvalue" }
>
> node webserver { $var = "value"
>
> include snmp, dns, classx
>
> }
>
> In this example classx ends up using $var = "value" but I want to
use
> the "newvalue". Is this possible?
Variable assignments always only propagate "downwards" in the
hierarchy. Thus,
to archieve your goal, this would have to llok like this:
| $var = "value"
|
| class webserver {
| include snmp, dns, classx
| }
|
| node ''other.server.com'' {
| $var = "newvalue"
| include webserver
| }
As long as you don''t need to modify the resources of webserver in the
children, you''re set. For the rare cases where I need to modify
behaviour of
a generic class, I have found two cases. First, if the change is small and of
general interest, I either introduce a additional configuration variable,
which can then be set in the node scope. Secondly, for one-off changes, I
just create a new class, inheriting. E.g.:
| class dbp::with_ppp inherits dbp {
| Package[ppp] { ensure => installed }
| }
|
| node modemserver {
| $... = ...
| include dbp::with_ppp
| }
MfG David
- --
The primary freedom of open source is not the freedom from cost, but the free-
dom to shape software to do what you want. This freedom is /never/ exercised
without cost, but is available /at all/ only by accepting the very different
costs associated with open source, costs not in money, but in time and effort.
- -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHCePC/Pp1N6Uzh0URAp70AKCHYNsv1vlO7N5r3kL9X7sd/vMkbgCZAWiv
3vh0xRYdQFZOXQx/cB1B6ZM=G1zv
-----END PGP SIGNATURE-----