Skip to content

Commit 7d2e807

Browse files
committed
permit use of mysql::db without mysql::server
This removes the hard dependencies on mysql::server from manifests/db.pp. This permits one to use this module to manage databases in an existing server, possibly located on a remote host (with a properly configured /root/.my.cnf). The dependencies are instead placed in mysql/server.pp and are implemented using collectors, so that the dependencies are only created if mysql::server is realized.
1 parent 467017a commit 7d2e807

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ replicate-do-db = base2
106106
To add custom MySQL configuration, drop additional files into
107107
`/etc/mysql/conf.d/`. Dropping files into conf.d allows you to override settings or add additional ones, which is helpful if you choose not to use `override_options` in `mysql::server`. The conf.d location is hardcoded into the my.cnf template file.
108108

109+
###Working with an existing server
110+
111+
It is possible to use the MySQL module to instantiate databases and
112+
users on an existing MySQL server. For this to work, you will need an
113+
appropriate `.my.cnf` in `root`'s home directory containing the remote
114+
server address and credentials. For example:
115+
116+
[client]
117+
user=root
118+
host=localhost
119+
password=secret
120+
121+
When working with a remote server, you will *not* use the
122+
`mysql::server` class in your Puppet manifests.
123+
109124
##Reference
110125

111126
###Classes

manifests/db.pp

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323
charset => $charset,
2424
collate => $collate,
2525
provider => 'mysql',
26-
require => [ Class['mysql::server'], Class['mysql::client'] ],
26+
require => [ Class['mysql::client'] ],
2727
}
2828
ensure_resource('mysql_database', $dbname, $db_resource)
2929

3030
$user_resource = {
3131
ensure => $ensure,
3232
password_hash => mysql_password($password),
3333
provider => 'mysql',
34-
require => Class['mysql::server'],
3534
}
3635
ensure_resource('mysql_user', "${user}@${host}", $user_resource)
3736

@@ -41,7 +40,10 @@
4140
provider => 'mysql',
4241
user => "${user}@${host}",
4342
table => $table,
44-
require => [Mysql_database[$dbname], Mysql_user["${user}@${host}"], Class['mysql::server'] ],
43+
require => [
44+
Mysql_database[$dbname],
45+
Mysql_user["${user}@${host}"],
46+
],
4547
}
4648

4749
$refresh = ! $enforce_sql

manifests/server.pp

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,8 @@
7878
Anchor['mysql::server::end']
7979
}
8080

81-
81+
Class['mysql::server'] -> Mysql_database <||>
82+
Class['mysql::server'] -> Mysql_user <||>
8283
}
84+
85+

0 commit comments

Comments
 (0)