Skip to content

Instantly share code, notes, and snippets.

@lusis
Created March 11, 2011 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lusis/865645 to your computer and use it in GitHub Desktop.
Save lusis/865645 to your computer and use it in GitHub Desktop.
if u.has_key?("mysql_permissions") and u[:mysql_permissions].has_key?(node.name) then
u[:mysql_permissions]["#{node.name}"].each do |database, grants|
Chef::Log.info("Found permission on #{node.name} for #{u[:id]}: DB: #{database}, Grants: #{grants.join(',')}")
execute "grant-#{u[:id]}-#{database}-perms" do
command "/usr/bin/mysql -u root -p#{mysql_password} -D mysql -r -B -N -e \"GRANT #{grants.join(',')} ON #{database}.* to '#{u[:id]}'@'localhost'\""
action :run
not_if { `/usr/bin/mysql -u root -p#{mysql_password} -D mysql -r -B -N -e \"SELECT COUNT(*) FROM user where User='#{u[:id]}' and Host = 'localhost'"`.to_i == 0 }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment