Muhammad Rehan Saeed
Muhammad Rehan Saeed

Reputation: 38417

How to Require Another Custom Class Using Puppet

If I have two class's in my own puppet module and class 'b' has a dependency on class 'a'. How can I express this in my require statement:

# a.pp
class rehan::a {
    package { 'javaruntime':
        ensure   => latest,
        provider => chocolatey
    }
}

# b.pp
class rehan::b {
    file { 'C:\foo':
        ensure  => present,
        require => Package['?????']
    }
}

# site.pp
node default {
    include rehan::a
    include rehan::b
}

Upvotes: 5

Views: 14453

Answers (1)

Artefacto
Artefacto

Reputation: 97805

If you want to express a dependency of class b on class a (and also ensure that a is in the catalog):

class rehan::b {
    require rehan::a
}

If you just one resource on rehan::b to depend on class A:

class rehan::b {
    include rehan::a  # ensure the class is in the catalog
    file { 'C:\foo':
        ensure  => present,
        require => Class['rehan::a'],
    }
}

You can also express this relationship anywhere with Class['rehan::a'] -> Class['rehan::b'] (assuming both are included in the catalog).

Upvotes: 11

Related Questions