I have been trying to get my head around the changes in the chef mysql cookbook (https://github.com/chef-cookbooks/mysql) between version 5.x and version 6.x, and I am struggling a little bit.
I have it successfully installing, but I don't understand how to use the default my.cnf template provided by the cookbook. Because it's in a different cookbook, my database recipe can't find it. I tried copying it to my cookbook, but when I do that the @config variable is not initialized, so it has a fatal error.
Here's what my database recipe looks like at the moment (basically the example provided in the README):
mysql_service 'default' do
port '3306'
version '5.5'
initial_root_password 'change me'
action [:create, :start]
end
mysql_config 'default' do
source 'my.cnf.erb'
notifies :restart, 'mysql_service[default]'
action :create
end
Following the suggestions in the replies, I now have this for my mysql_config:
mysql_config 'default' do
source 'my.cnf.erb'
cookbook 'mysql'
variables :config => {
:name => "mysql",
:port => 3306,
:user => "mysql"
},
:pid_file => "/var/run/mysqld/mysqld.pid",
:socket_file => "/var/run/mysqld/mysqld.sock",
:include_dir => "/etc/mysql/conf.d/"
notifies :restart, 'mysql_service[default]'
action :create
end
which returns this error:
Chef::Mixin::Template::TemplateError (undefined method `name' for {:name=>"mysql", :port=>3306, :user=>"mysql"}:Hash) on line #1:
1: # Chef generated my.cnf for instance mysql-<%= @config.name %>
2:
3: [client]
4: <% if @config.charset %>
5: default-character-set = <%= @config.charset %>
I also placed my cookbooks for this minimal example up in github: https://github.com/rhuffstedtler/chef-mysql-database-example