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

I have a puppet definition that runs an exec type to create a mysql user that looks like this:

define mysql::mysql-user ($user, $host="$mysql_subnet", $passwd="", $ensure="present") {
    exec { "mysql -e \"CREATE USER '$user'@'$host' IDENTIFIED BY PASSWORD '$passwd'\"":
        path    => "/usr/bin:/bin",
        unless => "mysql -e \"SELECT Host,User FROM mysql.user WHERE Host='$host' AND User='$user'\" | grep $user",
        require => Service[ mysql ], 
    }
}

So, I want to make the $ensure argument work properly, calling a completely different exec to drop the user. What's the best way to go about this?

I've tried the following setup:

define mysql::mysql-user ($user, $host="$mysql_subnet", $passwd="", $ensure="present") {
    case $ensure {
        present:    { include add-user }
        absent:     { include remove-user }
    }
}

class mysql::add-user {
    exec { ... }
}

class mysql::remove-user {
    exec { ... }
}

but this fails because my grants definition (not shown) is now somehow no longer dependent on mysql-user running first.

share|improve this question

1 Answer 1

up vote 3 down vote accepted
define blah($ensure = present) {
    if $ensure == "present" {
        exec { do_something_to_make_it_be_here: }
    } else {
        exec { do_something_to_make_it_not_be_here: }
    }
}

For more than just ensure present/absent, you can switch to a case in the same vein. Don't go to subclasses, because as you say they lose dependency information.

share|improve this answer
    
Cheers for the help! –  Daniel Zollinger Aug 18 '09 at 4:16

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.