pass Resources to a define or unsetting notify

468 views
Skip to first unread message

Peter Meier

unread,
Mar 22, 2008, 3:03:40 PM3/22/08
to puppet...@googlegroups.com
Hi

i'm trying to pass Resources (single or in an array) to a resource, so I
can pass this to a notify or require. However I have some problems, when
no resource should be passed. Maybe somebody can help me? thanks

define gentoo::etcconfd (
$require = '',
$notify = ''
){
file { "/etc/conf.d/${name}":
owner => "root",
group => "0",
mode => 644,
source => [
"puppet://$server/dist/gentoo/etc_conf.d/${name}_${fqdn}",
"puppet://$server/dist/gentoo/etc_conf.d/${name}_default",
"puppet://$server/gentoo/etc_conf.d/${name}"
],
require => $require,
notify => $notify,
}
}

#works not:
gentoo::etcconfd { foobar: }
#works:
gentoo::etcconfd { apache2: require => "Package[apache]", notify =>
"Service[apache]"}

#Error I get:
err: Could not create /etc/conf.d/foobar: Parameter require failed:
interning empty string

I also tried setting it to undef, which didn't change anything.

Or should I use a trick to pass the resource?

thanks for your help and greets pete

Ashley Penney

unread,
Mar 22, 2008, 3:20:31 PM3/22/08
to puppet...@googlegroups.com
I'm no expert, but why don't you try wrapping the require => $require statments with an 'if $require', just to make sure it only tries to set it if the variable exists.  That way if you don't pass a $require, it won't exist and should work!

Luke Kanies

unread,
Mar 22, 2008, 4:35:56 PM3/22/08
to puppet...@googlegroups.com
On Mar 22, 2008, at 2:03 PM, Peter Meier wrote:

>
> Hi
>
> i'm trying to pass Resources (single or in an array) to a resource,
> so I
> can pass this to a notify or require. However I have some problems,
> when
> no resource should be passed. Maybe somebody can help me? thanks
>
> define gentoo::etcconfd (
> $require = '',
> $notify = ''
> ){

You don't need to declare these (in fact, you should be seeing a
warning for them); all defined types automatically support all
metaparameters.

Otherwise, follow the advice of the other poster: default to false,
and test for the value before you go ahead and set it on the
resource. That won't work for metaparameters, because resources
automatically acquire all metaparameters from the definition they're in.

--
A bore is a man who deprives you of solitude without providing you
with company. -- Gian Vincenzo Gravina
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

Peter Meier

unread,
Mar 23, 2008, 6:18:44 AM3/23/08
to puppet...@googlegroups.com
Hi

> You don't need to declare these (in fact, you should be seeing a
> warning for them); all defined types automatically support all
> metaparameters.

ah cool. Didn't know that. I tried to add this to the Language Tutorial:
http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial?action=diff&version=45
I hope that this might be ok?! Otherwise please change/correct it.

> Otherwise, follow the advice of the other poster: default to false,
> and test for the value before you go ahead and set it on the
> resource. That won't work for metaparameters, because resources
> automatically acquire all metaparameters from the definition they're in.


this works now: :)

define gentoo::etcconfd (){


file { "/etc/conf.d/${name}":
owner => "root",
group => "0",
mode => 644,
source => [
"puppet://$server/dist/gentoo/etc_conf.d/${name}_${fqdn}",
"puppet://$server/dist/gentoo/etc_conf.d/${name}_default",
"puppet://$server/gentoo/etc_conf.d/${name}"
],
}

if $require {
File["/etc/conf.d/${name}"]{
require => $require,
}
}
if $notify {
File["/etc/conf.d/${name}"]{
notify => $notify,
}
}
}


thanks a lot!

greets pete

James Turnbull

unread,
Mar 23, 2008, 10:56:06 AM3/23/08
to puppet...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter Meier wrote:
| Hi
|
|> You don't need to declare these (in fact, you should be seeing a
|> warning for them); all defined types automatically support all
|> metaparameters.
|
| ah cool. Didn't know that. I tried to add this to the Language Tutorial:
|
http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial?action=diff&version=45
| I hope that this might be ok?! Otherwise please change/correct it.
|

Might want to include an example and a bit more information - the
Tutorial is designed as an introduction.

Regards

James Turnbull

- --
James Turnbull (ja...@lovedthanlost.net)
- --
Author of:
- - Pulling Strings with Puppet
(http://www.amazon.com/gp/product/1590599780/)
- - Pro Nagios 2.0
(http://www.amazon.com/gp/product/1590596099/)
- - Hardening Linux
(http://www.amazon.com/gp/product/1590594444/)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFH5m+G9hTGvAxC30ARApNkAKCbYIYKB4cWK/KY1dWYybhyyiGnVQCgubsH
rDuxxxQrhEF7dor8MzMZwU8=
=P39y
-----END PGP SIGNATURE-----

Brice Figureau

unread,
Mar 28, 2008, 9:26:06 AM3/28/08
to puppet...@googlegroups.com
Hi,

On Sat, 2008-03-22 at 15:35 -0500, Luke Kanies wrote:
> On Mar 22, 2008, at 2:03 PM, Peter Meier wrote:
>
> >
> > Hi
> >
> > i'm trying to pass Resources (single or in an array) to a resource,
> > so I
> > can pass this to a notify or require. However I have some problems,
> > when
> > no resource should be passed. Maybe somebody can help me? thanks
> >
> > define gentoo::etcconfd (
> > $require = '',
> > $notify = ''
> > ){
>
> You don't need to declare these (in fact, you should be seeing a
> warning for them); all defined types automatically support all
> metaparameters.

What is not clear to me, is if the resources in the define section
inherits the metaparameters or if we have to "propagate" them by hand?

In other words, should I do:
ex:
define my_definition() {
file {
...
}
exec {
...
}
}

or
define my_definition() {
file {
...
require => $require
}
exec {
...
require => $require
}
}

It was my understanding that they fully propagate, but I just want to be
sure it's really the case.

Thanks for clarifying,
--
Brice Figureau <brice-...@daysofwonder.com>

Luke Kanies

unread,
Mar 28, 2008, 10:45:30 AM3/28/08
to puppet...@googlegroups.com
On Mar 28, 2008, at 8:26 AM, Brice Figureau wrote:

> What is not clear to me, is if the resources in the define section
> inherits the metaparameters or if we have to "propagate" them by hand?
>
> In other words, should I do:
> ex:
> define my_definition() {
> file {
> ...
> }
> exec {
> ...
> }
> }
>
> or
> define my_definition() {
> file {
> ...
> require => $require
> }
> exec {
> ...
> require => $require
> }
> }
>
> It was my understanding that they fully propagate, but I just want
> to be
> sure it's really the case.


This really is very easy to test:

define mptest {
notify { "this is a $name test": }
}

mptest { yay: loglevel => warning }

Prints:

warning: this is a yay test

Notice the loglevel.

--
This book fills a much-needed gap. -- Moses Hadas

Reply all
Reply to author
Forward
0 new messages