Overriding resources created with a define

328 views
Skip to first unread message

John T. Guthrie

unread,
Jan 8, 2010, 3:06:02 PM1/8/10
to Puppet Users
Hello all,

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

Trevor Vaughan

unread,
Jan 8, 2010, 3:29:35 PM1/8/10
to puppet...@googlegroups.com, John T. Guthrie
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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-----

John T. Guthrie

unread,
Jan 8, 2010, 3:50:09 PM1/8/10
to Trevor Vaughan, puppet...@googlegroups.com
Hello all,

First, I would like to thank you for your suggestion about an 'if/case' statement.  I think that should do what I want.  However, I would think that even if defines are scoped separately from classes, that wouldn't necessarily apply in the case that I outlined below since I used a different define name in the subclass as opposed to the name for the define in the parent class.  I was trying to get a resource override into a define.  Is that not possible; i.e., can defines only handle resource definitions, but not overrides?

Thanks.

John Guthrie

Trevor Vaughan

unread,
Jan 8, 2010, 4:00:21 PM1/8/10
to John T. Guthrie, puppet...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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-----

Reply all
Reply to author
Forward
0 new messages