James Sapam
James Sapam

Reputation: 16940

how to write puppet class dependency on the status of another class

I ve two class called main.pp and precheck.pp. My idea is main.pp will continue execute if the precheck.pp is succeed. So, how should I get the status of precheck.pp

class my::main {
   require my::module::precheck
   # I want to execute installpackage if precheck is succeed.
   require my::module::installpackage
}

And in precheck.pp

class my::module::precheck {
       if $facts['osfamily'] == 'redhat' {
        if versioncmp($facts['operatingsystemmajrelease'], '7') >= 0 {
            notify {"osrelease":
                message => "${::operatingsystemmajrelease} is good to install myapp."
            }
        }
        else {
            fail("myapp is not supported on this OS release")
        }
    }
    else {
         fail("myapp is not supported on ${::osfamily}.")
    }
} 

The above snippet is not working as expected.

thanks James

Upvotes: 0

Views: 115

Answers (1)

Matthew Schuchard
Matthew Schuchard

Reputation: 28774

You can create class level dependencies by utilizing the chaining arrow syntax:

class my::main {
  require my::module::precheck
  require my::module::installpackage
  my::module::precheck -> my::module::installpackage
}

This will create a dependency for the installpackage class container on the precheck class container. Note that class level dependencies in conjunction with class containers is generally not considered best practices though.

Upvotes: 1

Related Questions