On Thursday, February 14, 2013 5:10:43 AM UTC-6, Andriy Yurchuk wrote:
>
> Found out that it's very simple: subscribe => Class['module::class_2']
>
> On Thursday, February 14, 2013 12:20:30 PM UTC+2, Andriy Yurchuk wrote:
>>
>> class module::class_1 {
>>   service {
>>     ensure => running,
>>     hasrestart => true,
>>     subscribe => File[/tmp/myfile],
>>   }
>> }
>>
>> class module::class_2 {
>>   file { '/tmp/myfile':
>>          source => 'puppet:///file_server/my_file',
>>   }
>> }
>>
>> Having those two classes, how do I correctly write the subscribeparameter in 
>> class_1 so that it used the file resource from class_2?
>>
>

Although you can subscribe to the whole class, that's often not what you 
want, as it really means subscribing to every resource declared by that 
class.  If only one resource is declared then that's no problem, but many 
classes are more complicated.

A very important point here is that resources are global once they are 
declared. Any resource, declared anywhere, can declare a relationship to 
any other resource, declared anywhere else, and the sites of the 
declarations do not factor into the syntax.  The syntax in your example is 
correct.

On the other hand, it is important to ensure that resources are declared 
before references to them are used.  If a resource declared in one class is 
going to declare a relationship to a resource declared in a different one, 
then you must make sure that the latter class is parsed before the former 
one's resource declaration.  As long as the latter class is not 
parametrized, the easiest and best way to accomplish that is for the former 
class to 'include' the latter at the top of its body:

class module::class_1 {
  include 'module::class_2'
  service {
    ensure => running,
    hasrestart => true,
    subscribe => File[/tmp/myfile],
  }
}

That also has the advantage of documenting the dependency between the two 
classes.  For it to work properly, however, you should arrange your classes 
each in its own file, laid out in the way the autoloader expects.


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 puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to