added MySQL

This commit is contained in:
William Mantly 2019-06-30 17:28:00 -04:00
parent 15bee53bdf
commit d3339a49a6
Signed by: wmantly
GPG Key ID: E1EEC7650BA97160
3 changed files with 29 additions and 1 deletions

6
attributes/mysql.rb Normal file
View File

@ -0,0 +1,6 @@
require 'securerandom'
node.default['db']['name'] = "#{node['app']['name']}"
node.default['db']['user'] = "#{node['app']['name']}"
node.default['db']['root_password'] = SecureRandom.hex(13)
node.default['db']['password'] = SecureRandom.hex(13)

View File

@ -4,11 +4,12 @@ maintainer_email 'you@example.com'
license 'All Rights Reserved'
description 'Installs/Configures t42-common'
long_description 'Installs/Configures t42-common'
version '0.1.4'
version '0.1.5'
chef_version '>= 13.0'
depends 'nodejs'
depends 'postgresql'
depends 'mysql'
# The `issues_url` points to the location where issues for this cookbook are
# tracked. A `View Issues` link will be displayed on this cookbook's page when

21
recipes/mysql.rb Normal file
View File

@ -0,0 +1,21 @@
mysql_service node['db']['name'] do
# version '5.7'
bind_address '127.0.0.1'
port '3306'
# data_dir '/data'
initial_root_password node['db']['root_password']
action [:create, :start]
end
bash 'Make mysql Database and User' do
code <<~EOH
mysql -h 127.0.0.1 -uroot -p"#{node['db']['root_password']}" -e "CREATE DATABASE #{node['db']['user']} /*\!40100 DEFAULT CHARACTER SET utf8 */;"
mysql -h 127.0.0.1 -uroot -p"#{node['db']['root_password']}" -e "CREATE USER #{node['db']['user']}@localhost IDENTIFIED BY '#{node['db']['password']}';"
mysql -h 127.0.0.1 -uroot -p"#{node['db']['root_password']}" -e "GRANT ALL PRIVILEGES ON #{node['db']['user']}.* TO '#{node['db']['user']}'@'localhost';"
mysql -h 127.0.0.1 -uroot -p"#{node['db']['root_password']}" -e "FLUSH PRIVILEGES;"
EOH
not_if "mysql -h 127.0.0.1 -uroot -p\"#{node['db']['root_password']}\" -e 'use #{node['db']['name']}'"
end