I am using the following and it serves us well. Basically it makes sure
that the importing is done and executes '&& touch semaphore' file. There
are plans to put those into /var/lib/puppet/sql-snippets instead of in
/opt but oh well it seems I am too lazy to go and move them on each
server now...
<snip>
class sql {
$sqls = '/opt/sql-snippets'
file { $sql::sqls:
ensure => directory,
mode => "700",
}
define do($source='', $db, $content='') {
$script = "$sql::sqls/$name.sql"
file { $script:
mode => "600",
}
case $content {
'': {
File[$script] {
source => $source
}
}
default: {
File[$script] {
content => $content
}
}
}
exec {"mysql-import-$name":
path => ['/bin', '/sbin', '/usr/bin'],
command => "mysql --defaults-file=/root/.my.cnf $db < $script && touch $script.semaphore",
creates => "$script.semaphore",
require => File[$script],
timeout => '0',
}
}
define source($local_script_path, $db) {
$semaphore = "$sql::sqls/$name.semaphore"
exec { "mysql-execute-script-$name":
path => ['/bin', '/sbin', '/usr/bin'],
command => "mysql --defaults-file=/root/.my.cnf $db < $local_script_path && touch $semaphore",
creates => "$semaphore",
timeout => '0',
}
}
Class['mysql'] -> Class['sql']
}
<snip>
Note that it requires a mysql class to be defined before that.
You will get bonus points if you make it work for other databases like
postgre and what not
Some problems:
* the name of the sql::do or sql::sourc should be lowercase as i don't
want to support that(if you want put quotes around semaphore in the
touch
--
Nikola
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To view this discussion on the web visit
https://groups.google.com/d/msg/puppet-users/-/Csk_kOJXTtcJ.
> To post to this group, send email to
puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
puppet-users...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
>