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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ For detailed info about the logic and usage patterns of Example42 modules read R
root_password => 'auto',
}

* Create a new grant and database
* Create a new grant and database. mysql_db_init_query_file is optional and will run only once.

mysql::grant { 'db1':
mysql_privileges => 'ALL',
mysql_password => 'pwd',
mysql_db => 'db1',
mysql_user => 'db1',
mysql_host => 'host',
mysql_db_init_query_file => '/full/path/to/the/schema.sql',
}


Expand Down
34 changes: 19 additions & 15 deletions manifests/grant.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
# grant statement and then applies it.
#
# Supported arguments:
# $mysql_db - The database to apply the grant to.
# If not set, defaults to == $title
# It supports SQL wildcards (%), ie: 'somedatab%'.
# The special value '*' means 'ALL DATABASES'
# $mysql_user - User to grant the permissions to.
# $mysql_password - Plaintext password for the user.
# $mysql_create_db - If you want a $mysql_db database created or not.
# Default: true.
# $mysql_privileges - Privileges to grant to the user.
# Defaults to 'ALL'
# $mysql_host - Host where the user can connect from. Accepts SQL wildcards.
# Default: 'localhost'
# $mysql_grant_filepath - Path where the grant files will be stored.
# Default: '/root/puppet-mysql'
# $mysql_db - The database to apply the grant to.
# If not set, defaults to == $title
# It supports SQL wildcards (%), ie: 'somedatab%'.
# The special value '*' means 'ALL DATABASES'
# $mysql_user - User to grant the permissions to.
# $mysql_password - Plaintext password for the user.
# $mysql_create_db - If you want a $mysql_db database created or not.
# Default: true.
# $mysql_privileges - Privileges to grant to the user.
# Defaults to 'ALL'
# $mysql_host - Host where the user can connect from. Accepts SQL wildcards.
# Default: 'localhost'
# $mysql_grant_filepath - Path where the grant files will be stored.
# Default: '/root/puppet-mysql'
# $mysql_db_init_query_file - Location of a sql file typically used to create the schema.
# $mysql_create_db must be true or the database must exist.
# Default: ''
define mysql::grant (
$mysql_user,
$mysql_password,
Expand Down Expand Up @@ -96,13 +99,14 @@
refreshonly => true;
}

if $mysql_db_init_query_file != '' {
if $mysql_db_init_query_file != '' and $mysql_create_db == true {
mysql::queryfile { "mysql_db_init_query_file-${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}"],
}
}
}