FAQ
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 subscribe parameter
in class_1 so that it used the file resource from class_2?

--
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+unsubscribe@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.

Search Discussions

  • Andriy Yurchuk at Feb 14, 2013 at 11:18 am
    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?
    --
    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+unsubscribe@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.
  • Jcbollinger at Feb 14, 2013 at 2:32 pm

    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+unsubscribe@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.
  • Andriy Yurchuk at Feb 15, 2013 at 3:26 pm
    Thanks a lot John, the explanation was really helpful.
    On Thursday, February 14, 2013 4:32:38 PM UTC+2, jcbollinger wrote:


    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+unsubscribe@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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedFeb 14, '13 at 10:27a
activeFeb 15, '13 at 3:26p
posts4
users2
websitepuppetlabs.com

2 users in discussion

Andriy Yurchuk: 3 posts Jcbollinger: 1 post

People

Translate

site design / logo © 2022 Grokbase