Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created January 29, 2014 22:09
Show Gist options
  • Save scottwb/8698176 to your computer and use it in GitHub Desktop.
Save scottwb/8698176 to your computer and use it in GitHub Desktop.
The Chef Community MySQL cookbook does not allow a mysql server with no root password when using chef-solo. That's how I like it for easy test VMs, so I made these change to it. Consider this an obvious change. Take it as you please. YMMV.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment