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

Fix tests and integrate MySQL module with Hiera #60

Merged
merged 2 commits into from
Mar 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Session.vim
spec/fixtures
.*.sw[a-z]
*.un~
/Gemfile.lock
/.bundle
36 changes: 27 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
language: ruby
bundler_args: --without development
rvm:
- 1.8.7
- 1.9.3
- 2.0.0
- 2.1.1
script:
- "rake spec SPEC_OPTS='--format documentation'"
- "bundle exec rake validate lint spec SPEC_OPTS='--format documentation'"
env:
- PUPPET_VERSION="~> 2.6.0"
- PUPPET_VERSION="~> 2.7.0"
- PUPPET_VERSION="~> 3.0.0"
- PUPPET_VERSION="~> 3.1.0"
- PUPPET_VERSION="~> 3.2.0"
- PUPPET_VERSION="~> 3.3.0"
- PUPPET_VERSION="~> 3.4.0"
- PUPPET_VERSION="~> 3.5.0"
- PUPPET_VERSION="~> 3.6.0"
- PUPPET_VERSION="~> 3.7.0"
matrix:
exclude:
# fails on can't convert String into Integer at init.pp:284
# fqdn_rand patch in
- rvm: 1.9.3
env: PUPPET_VERSION="~> 2.6.0"
gemfile: .gemfile.travis
- rvm: 1.9.3
env: PUPPET_VERSION="~> 2.7.0"
gemfile: .gemfile.travis

gemfile: .gemfile
# fails on "Could not autoload package: constant Puppet::Type::Package"
- rvm: 2.0.0
env: PUPPET_VERSION="~> 3.1.0"
# fails on iconv couldn't be loaded, which is required for UTF-8/UTF-16 conversions
- rvm: 2.0.0
env: PUPPET_VERSION="~> 2.7.0"
- rvm: 2.1.1
env: PUPPET_VERSION="~> 2.7.0"
# fails on "can't modify frozen Symbol"
- rvm: 2.1.1
env: PUPPET_VERSION="~> 3.1.0"
- rvm: 2.1.1
env: PUPPET_VERSION="~> 3.2.0"
- rvm: 2.1.1
env: PUPPET_VERSION="~> 3.3.0"
notifications:
email:
- [email protected]
17 changes: 17 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source 'https://rubygems.org'

puppetversion = ENV['PUPPET_VERSION']

is_ruby18 = RUBY_VERSION.start_with? '1.8'

if is_ruby18
gem 'rspec', "~> 3.1.0", :require => false
end
gem 'puppet', puppetversion, :require => false
gem 'puppet-lint'
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'rspec-puppet'

group :development do
gem 'puppet-blacksmith'
end
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ For detailed info about the logic and usage patterns of Example42 modules read R
The simplest way to create database is the following.

mysql::grant { 'db1':
mysql_username => 'myusername',
mysql_user => 'myusername',
mysql_password => 'mypassword',
}

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

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

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

mysql::grant { 'db1':
ensure => 'absent',
mysql_username => 'myusername',
mysql_user => 'myusername',
mysql_password => 'mypassword',
}

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

mysql::grant { 'db1':
ensure => 'absent',
mysql_username => 'myusername',
mysql_user => 'myusername',
mysql_password => 'mypassword',
mysql_db_init_query_file => '/full/path/to/the/schema.sql',
}
Expand Down Expand Up @@ -161,6 +161,26 @@ __NOTE__: The SQL file should already be uploaded on mysql server host.
my_class => 'mysql::example42',
}

## USAGE - Hiera Support
* Manage MySQL configuration using Hiera

```yaml
mysql::template: 'modules/mysql/my.cnf.erb'
mysql::root_password: 'example42'
mysql::options:
port: '3306'
bind-address: '127.0.0.1'
```

* Defining MySQL resources using Hiera

```yaml
mysql::grant_hash:
'db1':
mysql_user: 'myusername'
mysql_password: 'mypassword'
mysql_host: '10.42.42.0/255.255.255.0'
```

## USAGE - Example42 extensions management
* Activate puppi (recommended, but disabled by default)
Expand Down
2 changes: 1 addition & 1 deletion manifests/grant.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
) {

if $remote_host == '' {
require mysql
include mysql
}

$dbname = $mysql_db ? {
Expand Down
42 changes: 35 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,13 @@
$log_dir = params_lookup( 'log_dir' ),
$log_file = params_lookup( 'log_file' ),
$port = params_lookup( 'port' ),
$protocol = params_lookup( 'protocol' )
$protocol = params_lookup( 'protocol' ),
## Hiera lookup
$augeas_hash = {},
$grant_hash = {},
$query_hash = {},
$queryfile_hash = {},
$user_hash = {},
) inherits mysql::params {

$bool_source_dir_purge=any2bool($source_dir_purge)
Expand All @@ -279,6 +285,28 @@
$bool_debug=any2bool($debug)
$bool_audit_only=any2bool($audit_only)

## Integration with Hiera
if $augeas_hash != {} {
validate_hash($augeas_hash)
create_resources('mysql::augeas', $augeas_hash)
}
if $grant_hash != {} {
validate_hash($grant_hash)
create_resources('mysql::grant', $grant_hash)
}
if $query_hash != {} {
validate_hash($query_hash)
create_resources('mysql::query', $query_hash)
}
if $queryfile_hash != {} {
validate_hash($queryfile_hash)
create_resources('mysql::queryfile', $queryfile_hash)
}
if $user_hash != {} {
validate_hash($user_hash)
create_resources('mysql::user', $user_hash)
}

### Root password setup
$random_password = $mysql::password_salt ? {
'' => fqdn_rand(100000000000),
Expand Down Expand Up @@ -371,12 +399,12 @@

if $mysql::bool_absent == false {
service { 'mysql':
ensure => $mysql::manage_service_ensure,
name => $mysql::service,
enable => $mysql::manage_service_enable,
hasstatus => $mysql::service_status,
pattern => $mysql::process,
require => [ Package['mysql'] , File['mysql.conf'] ]
ensure => $mysql::manage_service_ensure,
name => $mysql::service,
enable => $mysql::manage_service_enable,
hasstatus => $mysql::service_status,
pattern => $mysql::process,
require => [ Package['mysql'] , File['mysql.conf'] ]
}
}

Expand Down
14 changes: 7 additions & 7 deletions manifests/password.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class mysql::password {

# Load the variables used in this module. Check the params.pp file
require mysql
require mysql::params
include mysql
include mysql::params

if ! defined(File['/root/.my.cnf']) {
file { '/root/.my.cnf':
Expand Down Expand Up @@ -35,11 +35,11 @@
}

exec { 'mysql_backup_root_my_cnf':
require => Service['mysql'],
path => '/bin:/sbin:/usr/bin:/usr/sbin',
unless => 'diff /root/.my.cnf /root/.my.cnf.backup',
command => 'cp /root/.my.cnf /root/.my.cnf.backup ; true',
before => File['/root/.my.cnf'],
require => Service['mysql'],
path => '/bin:/sbin:/usr/bin:/usr/sbin',
unless => 'diff /root/.my.cnf /root/.my.cnf.backup',
command => 'cp /root/.my.cnf /root/.my.cnf.backup ; true',
before => File['/root/.my.cnf'],
}


Expand Down