Created
January 29, 2014 22:09
-
-
Save scottwb/8698176 to your computer and use it in GitHub Desktop.
Revisions
-
scottwb created this gist
Jan 29, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ diff --git a/cookbooks/mysql/libraries/helpers.rb b/cookbooks/mysql/libraries/he index c850233..1a5d99c 100644 --- a/cookbooks/mysql/libraries/helpers.rb +++ b/cookbooks/mysql/libraries/helpers.rb @@ -30,15 +30,18 @@ module Opscode end def assign_root_password_cmd + return nil unless node['mysql']['server_root_password'] str = '/usr/bin/mysqladmin' str << ' -u root password ' str << node['mysql']['server_root_password'] end def install_grants_cmd + password = node['mysql']['server_root_password'] + password_is_blank = password.nil? || password.empty? str = '/usr/bin/mysql' str << ' -u root ' - node['mysql']['server_root_password'].empty? ? str << ' < /etc/mysql_gr + password_is_blank ? str << ' < /etc/mysql_grants.sql' : str << " -p#{pa end end end diff --git a/cookbooks/mysql/recipes/_server_rhel.rb b/cookbooks/mysql/recipes/_ index b4d215a..1042f09 100644 --- a/cookbooks/mysql/recipes/_server_rhel.rb +++ b/cookbooks/mysql/recipes/_server_rhel.rb @@ -46,11 +46,12 @@ execute '/usr/bin/mysql_install_db' do only_if { node['platform_version'].to_i < 6 } end -cmd = assign_root_password_cmd -execute 'assign-root-password' do - command cmd - action :run - only_if "/usr/bin/mysql -u root -e 'show databases;'" +if cmd = assign_root_password_cmd + execute 'assign-root-password' do + command cmd + action :run + only_if "/usr/bin/mysql -u root -e 'show databases;'" + end end template '/etc/mysql_grants.sql' do diff --git a/cookbooks/mysql/recipes/server.rb b/cookbooks/mysql/recipes/server. index 8a57638..8f5a1fe 100644 --- a/cookbooks/mysql/recipes/server.rb +++ b/cookbooks/mysql/recipes/server.rb @@ -28,8 +28,9 @@ if Chef::Config[:solo] ].select { |attr| node['mysql'][attr].nil? }.map { |attr| %Q{node['mysql']['# unless missing_attrs.empty? - Chef::Application.fatal! "You must set #{missing_attrs.join(', ')} in chef- - " For more information, see https://github.com/opscode-cookbooks/mysql#chef + log "MySQL root user will not require a password." do + level :warn + end end else # generate all passwords