2

I'd like to place a custom configured /etc/my.cnf ONLY if the default my.conf is currently in place. Once the default my.cnf has been replaced or edited, I don't want to risk replacing it with my customized my.cnf.

My best ideas, and the drawbacks I see:

Take a checksum of the default my.cnf file, and if it matches that checksum, replace it. This seems the safest, but also annoying when there are new versions or minor changes to my.cnf

Look for text in my.cnf that only the default file includes, and none of my replacement my.cnf files would include. This seems slightly less annoying than my first option, but more risky.

Use a handler to replace my.cnf when mysql is installed. This could have disastrous consequences if I (or someone else) change the mysql requirement from "present" to "latest". I also worry about oddities I may hit if I need to adjust for mysql package name changes (for example, now that mysql isn't included in centos anymore, the oracle repo now has "community" in all the package names).

I'm looking for other methods. If its something you've already coded, I'd appreciate examples as well.

Thanks!

Danny F
  • 498
  • 3
  • 10
  • 1
    I think it would make it easier to express the desired state, rather than the difference between current and proposed states. The terms you use are understandably vague ("my" configuration, "default" configuration, _etc_) - but if you consider that these refer to specific states, it would make it easier to write the conditional. _What_ aspect are you checking ? The time difference? content difference? Specific configuration levers? Try to nail this down and it will make it easier to answer the question. – Bruce Becker Nov 25 '18 at 08:50

1 Answers1

0

You should avoid it to manage "something" automatically that is also managed manually. In any case this will become have conflicts.

If you want to manage my.cnfautomatically, print a clear statement in the first line, that this file is managed automatically. Any manual changes are getting lost. And that is ok.

If you want to have also manual configurations, then use include directives or something like that to include subdirs. There a user could override your automatic settings. There is often enough now a conf.d folder which contains user specific settings. In most my.cnf there is a line at the end with:

!includedir /etc/mysql/conf.d/

Another option is to use lineinfile. This is mostly enough if you only need to change some settings.

Also - if you plan to manage the configuration of your services with Ansible - also plan to manage the installation of your services. If you have significant changes in the configuration from one version of the service to the next version - either use different roles for managing that service or use a test environment to test you install and new configuration files.

TRW
  • 488
  • 3
  • 16