On Friday, April 1, 2016 at 4:57:02 AM UTC-5, Afroz Hussain wrote:
>
> Hi Martin,
>
> Thanks for your help. I have tried your hack but didn't work, still same
> error,
> class addfile (
> $enable_notify => Service[’tomcat’],
> ) {
> file {‘/tmp/hello’:
> ensure => file,
> notify => $enable_notify,
> }
> }
>
> Technically, we can all any resource from any classes since all resources
> are unique across modules.
>
Yes, once declared, resources have global scope. You can refer to them
from any class, in any module or no module. Martin did not suggest
differently.
But the fact the you CAN access resources from anywhere does not mean it's
a good idea to do so. Whether it's reasonable in this particular case is
unclear, but doubtful, as for the most part the identities of the resources
declared by a given class should be considered implementation details of
that class, and depending on another class's implementation details makes
your class brittle.
That's not even the most significant problem here, however. Your
(original) Addfile class depends on there is a resource Service['tomcat']
declared for the target node. If this is sensible in all cases, then it
would be best for that class to take its own measures to ensure that its
requirement is satisfied, which would be best done by declaring the
appropriate class. For example, if Tomcat is managed via a "tomcat" class,
then you might use
class addfile {
include 'tomcat'
# ...
}
But that's a half measure. Remember that we should avoid depending on
implementation details of other classes. If you are prepared to rely on
the tomcat class to provide the needed service resource, then it is
probably best to make that class the target of the notification
relationship, instead of anything within that you rely on it to declare:
class addfile {
include 'tomcat'
file {"/tmp/hello":
ensure => file,
content => "hello"
}
~>
Class['tomcat']
}
Note, among other things, that that works fine if the name of the Tomcat
service differs from node to node, and that it does not break if the
service name changes (e.g. to "apache-tomcat") in the future.
Much of that is predicated on the idea that signaling Tomcat is a hard
requirement, however, and the nature of the error you reported suggests
that that might not be the case. If you want to use your Addfile class on
machines where Tomcat is not being managed, and on those machines,
therefore, not to notify Service['tomcat'], then you probably need a much
deeper re-design than just one class. Something along the lines of
Martin's suggested modification to your class could well be part of such a
redesign, but you need rather more.
Indeed, I suspect that the reason Martin's suggestion did not work for you
is that you do not appreciate how to use it. Modifying the class
definition as he described will not, in itself, make any difference at
all. To address your problem via his version of the class, you need to
also cause the correct data for the target node to be bound to the new
class parameter. But if that's as far as you go then it's just a stopgap.
I think you have deeper problems.
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/29f3ec07-5e5a-48c1-a46c-db16439f5b3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.