diff --git a/.gitignore b/.gitignore index 3d116dc..674d4be 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ Session.vim spec/fixtures .*.sw[a-z] *.un~ +/Gemfile.lock +/.bundle diff --git a/.travis.yml b/.travis.yml index 667053b..de40c51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: - al@lab42.it diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..0bb0e37 --- /dev/null +++ b/Gemfile @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 3efaf3a..bdddc24 100644 --- a/README.md +++ b/README.md @@ -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', } @@ -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', } @@ -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', } @@ -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', } @@ -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', } @@ -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) diff --git a/manifests/grant.pp b/manifests/grant.pp index b211801..f4616d1 100644 --- a/manifests/grant.pp +++ b/manifests/grant.pp @@ -49,7 +49,7 @@ ) { if $remote_host == '' { - require mysql + include mysql } $dbname = $mysql_db ? { diff --git a/manifests/init.pp b/manifests/init.pp index f569627..2e3a7f1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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) @@ -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), @@ -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'] ] } } diff --git a/manifests/password.pp b/manifests/password.pp index 6f89efd..50f4b96 100644 --- a/manifests/password.pp +++ b/manifests/password.pp @@ -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': @@ -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'], }