Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Chef/puppet are great tools for managing the configuration of individual hosts, but they seem to fall down slightly when a configuration has dependencies between hosts. For example, I'd like to have a web server configuration that tries to start an application, but only if the database has already been started (on another host). Is there some similar tool that allows configurations to be specified which span hosts, or are there some extra bits of chef or puppet that make this possible?

share|improve this question

2 Answers 2

One thing you could do would be export the application resource from the database host. It would not guarantee the database is running, but, then again, nothing will. After all, the database may be stopped afterwards, and Puppet wouldn't know a thing about it until the next time it runs.

It would look something like this, anyway:

node 'database' {
    service { 'mysql': ensure => running }
    @@apache2::app { 'myapp': 
        ensure => running,
        tag => 'appserver',
    }
}

node 'appserver' {
    Apache2::App <<| tag == "$hostname" |>>
}

If you combine this with Davey's suggestion, you could further tie starting the application to a test of the database:

    @@apache2::app { 'myapp': 
        ensure => running,
        dbtest => "$fqdn user database --password=12345",
        tag    => 'appserver',
    }

    define apache2::app(ensure = running, dbtest = '') {
        service { 'apache2':
            ensure  => $ensure
            require => $dbtest ? {
                ''      => undef,
                default => Exec['test database'],
            },
        },
        exec { "mysqlaccess $dbtest":
            alias => 'test database',
        }
    }
share|improve this answer

I think you could write a custom fact for puppet/facter to do that. Here is an explanation from the puppetlabs website:

http://projects.puppetlabs.com/projects/1/wiki/Adding_Facts

Basically, if you can write the test in ruby then you can create a fact and deploy it to your puppet clients.

share|improve this answer
    
Facts run locally, right? So this would be pretty strange to have a fact on one machine that actually told me whether something was running on another machine. –  kdt Apr 30 '11 at 16:14
    
I like to think of it this way: Can machine X provide me with database service. I'd write a fact that did something like "select sysdate from dual" from the DB on that machine. If it can then we proceed. If not then we do the failure action. –  davey May 1 '11 at 18:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.