Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.
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
12 changes: 7 additions & 5 deletions manifests/grant.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
default => "`${dbname}`",
}

$nice_mysql_host = regsubst($mysql_host, '/', '_')

$mysql_grant_file = $dbname ? {
/^(\*|%)$/ => "mysqlgrant-${mysql_user}-${mysql_host}-all.sql",
default => "mysqlgrant-${mysql_user}-${mysql_host}-${dbname}.sql",
/^(\*|%)$/ => "mysqlgrant-${mysql_user}-${nice_mysql_host}-all.sql",
default => "mysqlgrant-${mysql_user}-${nice_mysql_host}-${dbname}.sql",
}

# If dbname has a wildcard, we don't want to create anything
Expand Down Expand Up @@ -91,7 +93,7 @@
}


exec { "mysqlgrant-${mysql_user}-${mysql_host}-${dbname}":
exec { "mysqlgrant-${mysql_user}-${nice_mysql_host}-${dbname}":
command => $exec_command,
require => $exec_require,
subscribe => File[$mysql_grant_file],
Expand All @@ -100,13 +102,13 @@
}

if $mysql_db_init_query_file != '' and $mysql_create_db == true {
mysql::queryfile { "mysql_db_init_query_file-${mysql_host}-${dbname}":
mysql::queryfile { "mysql_db_init_query_file-${nice_mysql_host}-${dbname}":
mysql_file => $mysql_db_init_query_file,
mysql_user => $mysql_user,
mysql_password => $mysql_password,
mysql_db => $mysql_db,
mysql_host => $mysql_host,
subscribe => Exec["mysqlgrant-${mysql_user}-${mysql_host}-${dbname}"],
subscribe => Exec["mysqlgrant-${mysql_user}-${nice_mysql_host}-${dbname}"],
}
}
}
5 changes: 3 additions & 2 deletions manifests/user.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
}
}

$mysql_grant_file = "mysqluser-${mysql_user}-${mysql_host}.sql"
$nice_mysql_host = regsubst($mysql_host, '/', '_')
$mysql_grant_file = "mysqluser-${mysql_user}-${nice_mysql_host}.sql"

file { $mysql_grant_file:
ensure => present,
Expand All @@ -29,7 +30,7 @@
content => template('mysql/user.erb'),
}

exec { "mysqluser-${mysql_user}-${mysql_host}":
exec { "mysqluser-${mysql_user}-${nice_mysql_host}":
command => "mysql --defaults-file=/root/.my.cnf -uroot < ${mysql_grant_filepath}/${mysql_grant_file}",
require => [ Service['mysql'], File['/root/.my.cnf'] ],
subscribe => File[$mysql_grant_file],
Expand Down
14 changes: 14 additions & 0 deletions spec/defines/grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,18 @@
FLUSH PRIVILEGES ;
") }
end

describe 'Test grant all privileges on all databases (*) in an IP subnet. Should not create the databases' do
let(:facts) { { :mysql_root_password => 'rootpassword' } }
let(:params) { { :name => 'sample1',
:mysql_db => '*',
:mysql_host => '10.42.42.0/255.255.255.0',
:mysql_user => 'someuser',
:mysql_password => 'somepassword', } }
it { should contain_file('mysqlgrant-someuser-10.42.42.0_255.255.255.0-all.sql').with_content("# This file is managed by Puppet. DO NOT EDIT.
GRANT ALL ON *.* TO 'someuser'@'10.42.42.0/255.255.255.0' IDENTIFIED BY 'somepassword';
FLUSH PRIVILEGES ;
") }
it { should contain_exec('mysqlgrant-someuser-10.42.42.0_255.255.255.0-*').with_command('mysql --defaults-file=/root/.my.cnf -uroot < /root/puppet-mysql/mysqlgrant-someuser-10.42.42.0_255.255.255.0-all.sql') }
end
end