Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.

Commit 08fe850

Browse files
committed
Integrate MySQL module with Hiera and fix some lints
1 parent c206f29 commit 08fe850

File tree

4 files changed

+68
-20
lines changed

4 files changed

+68
-20
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ For detailed info about the logic and usage patterns of Example42 modules read R
3535
The simplest way to create database is the following.
3636

3737
mysql::grant { 'db1':
38-
mysql_username => 'myusername',
38+
mysql_user => 'myusername',
3939
mysql_password => 'mypassword',
4040
}
4141

@@ -45,7 +45,7 @@ This will create a MySQL database named 'db1' with a MySQL grant allowing full a
4545
If you want to customize the host the new user can connect from you have to use the 'mysql\_host'.
4646

4747
mysql::grant { 'db1':
48-
mysql_username => 'myusername',
48+
mysql_user => 'myusername',
4949
mysql_password => 'mypassword',
5050
mysql_host => '10.42.42.0/255.255.255.0',
5151
}
@@ -56,7 +56,7 @@ Here the whole 10.42.42.0/24 can connect.
5656
For privileges customization there is the 'mysql\_privileges' parameter.
5757

5858
mysql::grant { 'db1':
59-
mysql_username => 'myusername',
59+
mysql_user => 'myusername',
6060
mysql_password => 'mypassword',
6161
mysql_privileges => 'SELECT',
6262
}
@@ -68,7 +68,7 @@ Like for standard puppet resource you can use the 'ensure' parameter in order to
6868

6969
mysql::grant { 'db1':
7070
ensure => 'absent',
71-
mysql_username => 'myusername',
71+
mysql_user => 'myusername',
7272
mysql_password => 'mypassword',
7373
}
7474

@@ -79,7 +79,7 @@ The mysql\_db\_init\_query\_file is an optional parameter allowing to specify a
7979

8080
mysql::grant { 'db1':
8181
ensure => 'absent',
82-
mysql_username => 'myusername',
82+
mysql_user => 'myusername',
8383
mysql_password => 'mypassword',
8484
mysql_db_init_query_file => '/full/path/to/the/schema.sql',
8585
}
@@ -161,6 +161,26 @@ __NOTE__: The SQL file should already be uploaded on mysql server host.
161161
my_class => 'mysql::example42',
162162
}
163163

164+
## USAGE - Hiera Support
165+
* Manage MySQL configuration using Hiera
166+
167+
```yaml
168+
mysql::template: 'modules/mysql/my.cnf.erb'
169+
mysql::root_password: 'example42'
170+
mysql::options:
171+
port: '3306'
172+
bind-address: '127.0.0.1'
173+
```
174+
175+
* Defining MySQL resources using Hiera
176+
177+
```yaml
178+
mysql::grant_hash:
179+
'db1':
180+
mysql_user: 'myusername'
181+
mysql_password: 'mypassword'
182+
mysql_host: '10.42.42.0/255.255.255.0'
183+
```
164184
165185
## USAGE - Example42 extensions management
166186
* Activate puppi (recommended, but disabled by default)

manifests/grant.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
) {
5050

5151
if $remote_host == '' {
52-
require mysql
52+
include mysql
5353
}
5454

5555
$dbname = $mysql_db ? {

manifests/init.pp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,13 @@
264264
$log_dir = params_lookup( 'log_dir' ),
265265
$log_file = params_lookup( 'log_file' ),
266266
$port = params_lookup( 'port' ),
267-
$protocol = params_lookup( 'protocol' )
267+
$protocol = params_lookup( 'protocol' ),
268+
## Hiera lookup
269+
$augeas_hash = {},
270+
$grant_hash = {},
271+
$query_hash = {},
272+
$queryfile_hash = {},
273+
$user_hash = {},
268274
) inherits mysql::params {
269275

270276
$bool_source_dir_purge=any2bool($source_dir_purge)
@@ -279,6 +285,28 @@
279285
$bool_debug=any2bool($debug)
280286
$bool_audit_only=any2bool($audit_only)
281287

288+
## Integration with Hiera
289+
if $augeas_hash != {} {
290+
validate_hash($augeas_hash)
291+
create_resources('mysql::augeas', $augeas_hash)
292+
}
293+
if $grant_hash != {} {
294+
validate_hash($grant_hash)
295+
create_resources('mysql::grant', $grant_hash)
296+
}
297+
if $query_hash != {} {
298+
validate_hash($query_hash)
299+
create_resources('mysql::query', $query_hash)
300+
}
301+
if $queryfile_hash != {} {
302+
validate_hash($queryfile_hash)
303+
create_resources('mysql::queryfile', $queryfile_hash)
304+
}
305+
if $user_hash != {} {
306+
validate_hash($user_hash)
307+
create_resources('mysql::user', $user_hash)
308+
}
309+
282310
### Root password setup
283311
$random_password = $mysql::password_salt ? {
284312
'' => fqdn_rand(100000000000),
@@ -371,12 +399,12 @@
371399

372400
if $mysql::bool_absent == false {
373401
service { 'mysql':
374-
ensure => $mysql::manage_service_ensure,
375-
name => $mysql::service,
376-
enable => $mysql::manage_service_enable,
377-
hasstatus => $mysql::service_status,
378-
pattern => $mysql::process,
379-
require => [ Package['mysql'] , File['mysql.conf'] ]
402+
ensure => $mysql::manage_service_ensure,
403+
name => $mysql::service,
404+
enable => $mysql::manage_service_enable,
405+
hasstatus => $mysql::service_status,
406+
pattern => $mysql::process,
407+
require => [ Package['mysql'] , File['mysql.conf'] ]
380408
}
381409
}
382410

manifests/password.pp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
class mysql::password {
77

88
# Load the variables used in this module. Check the params.pp file
9-
require mysql
10-
require mysql::params
9+
include mysql
10+
include mysql::params
1111

1212
if ! defined(File['/root/.my.cnf']) {
1313
file { '/root/.my.cnf':
@@ -35,11 +35,11 @@
3535
}
3636

3737
exec { 'mysql_backup_root_my_cnf':
38-
require => Service['mysql'],
39-
path => '/bin:/sbin:/usr/bin:/usr/sbin',
40-
unless => 'diff /root/.my.cnf /root/.my.cnf.backup',
41-
command => 'cp /root/.my.cnf /root/.my.cnf.backup ; true',
42-
before => File['/root/.my.cnf'],
38+
require => Service['mysql'],
39+
path => '/bin:/sbin:/usr/bin:/usr/sbin',
40+
unless => 'diff /root/.my.cnf /root/.my.cnf.backup',
41+
command => 'cp /root/.my.cnf /root/.my.cnf.backup ; true',
42+
before => File['/root/.my.cnf'],
4343
}
4444

4545

0 commit comments

Comments
 (0)