I need to update mysql database configuration in remote nodes, I know I can use community.mysql.mysql_variables but that just not persists a server restart, to persist that settings to mysql**.cnf file, which module should I use?
I tried using community.general.ini_file module and it works, as mysql cnf files also have sections. But is it the preferred method ? Are cnf and ini files are same (I've googled that ini files are windows originated, but used in many configuration like the php.ini, cnf files proprietary to mysql and related dbms but are they same?)
I cannot use a fixed template as the end state, as some other configurations are different on the nodes.
I can create a custom config template file in the subdirectory which is to be included in the main config, but that is not a best way for a single configuration.
Also, what in the case of other key = value configuration files, such as
*.conffiles (which may or may not have sections, a quick example that comes to my mind is rabbitmq.conf, redis.conf - with # comments)*.envfiles - which can be custom or application specific (that also have # comments)
How can I manage the state of these files? What is the best way?
Note: I cannot just use the lineinfile module to add the line to EOF, because files like the my.cnf file have sections and the settings need to be under the desired section. Also, any extra character will cause a failure.
I wouldn't rely on the configuration file extension unless its documentation explicitly specifies its format and syntax.
If you want to manage the whole files and not their specific parts, then usage of templates and
templatemodule looks like a proper solution unless there is a module that is designed specifically for this purpose - I mean to manage the whole configuration, not to tweak the individual parameters likecommunity.general.ini_filedoes, for example.Ansible is basically designed exactly for that case. In a template you operate the variables. When you have multiple nodes, it's recommended to create an inventory, where you can assign different values (per group of hosts or individually per host) to the those variables. So you will end up with the same template that renders into customized configuration for each node. You can also set up those templates not to render some parts based on some variable value or its existence.