1
votes

I have a recipe that includes on mysql::server but replaces my.cnf file. The result is that on each chef-client run it restarts mysql server because my.cnf was replaced twice during chef-client run. How to avoid that?

Update: yes, this happens because mysql::server deploys my.cnf and then my recipe overwrites it. The question is how to disable deployment of my.cnf by mysql::server without disabling or modifying this cookbook (by using only changes in my wrapper-cookbook). Directly modifying community cookbooks is considered a bad practice so there surely should be a way to achieve desired behaviour using wrapping cookbook.

1
Why was it replaced twice? Surely the answer to this is by making sure there's only one resource declaration that touches my.cnf.cassianoleal
I suggest using the mysql_config resource listed in the mysql cookbook: supermarket.chef.io/cookbooks/mysqlMark O'Connor
What cookbook are you wrapping around? The "official" mysql cookbook that @MarkO'Connor linked to does not include a mysql::server recipe (in fact, it has no recipes at all). Your best bet would probably be to switch to that and declare mysql_service and mysql_config resources in your wrapper.cassianoleal
I user an older version of this recipe. I think mysql_config resource will fix my problem. But is there some general way to deal with similar situations?Poma
the mysql cookbook had a major update in v6.0 - they replaced all their recipes with LWRPsDerek

1 Answers

0
votes

By the sound of this, you have two template resources being declared for your my.cnf and one of them needs to be disabled.

Without the recipes I can only guess but this commonly occurs when you include the mysql::server recipe (which has it's own template resource for my.cnf) and then you specify your own template resource for my.cnf.

The MySQL cookbook allows you to define extra configuration using mysql_config Resource

mysql_service 'foo' do
  port '3306'
  version '5.5'
  initial_root_password 'change me'
  action [:create, :start]
end

mysql_config 'foo' do
  source 'my_extra_settings.erb'
  notifies :restart, 'mysql_service[foo]'
  action :create
end

You need to need to create my_extra_settings.erb in your cookbook