2

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?

2 Answers 2

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',
        }
    }
1

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.

2
  • 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, 2011 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.
    – gm3dmo
    May 1, 2011 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .