Suppose you have a resource that is created with a define such as the
following:
class test {
define myfile () {
file {
"/tmp/$name":
content => generate("/bin/echo","$name");
}
}
myfile {
"foo":
}
}
And it turns out that I want to create a subclass that overrides a
property of "/tmp/foo", how would I go about doing that? When I try to
add the following subclass:
class test::override inherits test {
define myfileover () {
File["/tmp/$name"] {
content => generate("/bin/echo","$name","$name")
}
}
myfileover {
"blah":
}
}
I get the following error:
Could not retrieve catalog: Only subclasses can override parameters at
/etc/puppet/network/prod/modules/test/manifests/init.pp:20 on node
xxxx. Does anyone have any suggestions?
Thanks.
John Guthrie
So, I believe (someone please correct me if I'm wrong) that defines are
actually separately scoped from the classes that contain them and cannot
currently be overridden.
The nesting that you have below is merely a convenience for writing:
define test::myfile () { ... }
I would suggest either using a template or an inline 'if/case' statement
to apply the logic you require.
Trevor
- --
Trevor Vaughan
Vice President, Onyx Point, Inc.
email: tvau...@onyxpoint.com
phone: 410-541-ONYX (6699)
- -- This account not approved for unencrypted sensitive information --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAktHla8ACgkQyWMIJmxwHpQFogCdG3y1B0j7FuS/TrQoixVWlY8R
pocAoJa5K20sHdW+T2q6g77WmdbD+7vY
=S4En
-----END PGP SIGNATURE-----
I think that the issue is that the define isn't actually scoped under
the class, so the inherit doesn't pick up that the file is actually
under that class at all. Does that make sense?
Try writing the same statement but move the defines outside of the
classes and I think you'll see exactly what I'm talking about.
Basically, you can't inherit defines (I think) because they actually
aren't derived from the Puppet Class object.
I.e. a Node is a subset of a Class, but a Define isn't.
Trevor
- --
Trevor Vaughan
Vice President, Onyx Point, Inc.
email: tvau...@onyxpoint.com
phone: 410-541-ONYX (6699)
- -- This account not approved for unencrypted sensitive information --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAktHnOUACgkQyWMIJmxwHpR/ZACbB3V9Sduw6jAiJb0P4CJkhviF
chAAoIfKFoH3PTU+cmFyltdWdC9xpodR
=5j7s
-----END PGP SIGNATURE-----