This repository was archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathqueryfile.pp
More file actions
51 lines (43 loc) · 1.45 KB
/
queryfile.pp
File metadata and controls
51 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Define mysql::queryfile
#
define mysql::queryfile (
$mysql_file,
$mysql_db = undef,
$mysql_user = '',
$mysql_password = '',
$mysql_host = '',
$mysql_query_filepath = '/root/puppet-mysql'
) {
if ! defined(File[$mysql_query_filepath]) {
file { $mysql_query_filepath:
ensure => directory,
}
}
$arg_mysql_user = $mysql_user ? {
'' => '',
default => "-u ${mysql_user}",
}
$arg_mysql_host = $mysql_host ? {
'' => '',
default => "-h ${mysql_host}",
}
$arg_mysql_password = $mysql_password ? {
'' => '',
default => "--password=\"${mysql_password}\"",
}
$arg_mysql_defaults_file = $mysql::real_root_password ? {
'' => '',
default => '--defaults-file=/root/.my.cnf',
}
$exec_require = $mysql::real_root_password ? {
'' => [ Service['mysql'], File[$mysql_query_filepath] ],
default => [ Service['mysql'], File[$mysql_query_filepath] , Class['mysql::password'] ],
}
exec { "mysqlqueryfile-${name}":
command => "mysql ${arg_mysql_defaults_file} ${arg_mysql_user} ${arg_mysql_password} ${arg_mysql_host} ${mysql_db} < ${mysql_file} && touch ${mysql_query_filepath}/mysqlqueryfile-${name}.run",
path => [ '/usr/bin' , '/usr/sbin' , '/bin' , '/sbin' ],
creates => "${mysql_query_filepath}/mysqlqueryfile-${name}.run",
unless => "ls ${mysql_query_filepath}/mysqlqueryfile-${name}.run",
require => $exec_require,
}
}