mirror of
https://github.com/saltstack-formulas/mysql-formula.git
synced 2025-04-15 17:20:25 +00:00
Add better support for a config directory with split config files.
This adds optional support for having split configuration files within a config directory, most commonly /etc/my.cnf.d.
This commit is contained in:
parent
a874ed3840
commit
0febad19c1
10 changed files with 273 additions and 16 deletions
|
@ -1,3 +1,6 @@
|
|||
include:
|
||||
- mysql.config
|
||||
|
||||
{% from "mysql/defaults.yaml" import rawmap with context %}
|
||||
{%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:lookup')) %}
|
||||
|
||||
|
|
70
mysql/config.sls
Normal file
70
mysql/config.sls
Normal file
|
@ -0,0 +1,70 @@
|
|||
{% from "mysql/defaults.yaml" import rawmap with context %}
|
||||
{%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:lookup')) %}
|
||||
{% set os_family = salt['grains.get']('os_family', None) %}
|
||||
|
||||
{% if "config_directory" in mysql %}
|
||||
mysql_config_directory:
|
||||
file.directory:
|
||||
- name: {{ mysql.config_directory }}
|
||||
{% if os_family in ['Debian', 'Gentoo', 'RedHat'] %}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 755
|
||||
{% endif %}
|
||||
- makedirs: True
|
||||
|
||||
{% if "server_config" in mysql %}
|
||||
mysql_server_config:
|
||||
file.managed:
|
||||
- name: {{ mysql.config_directory + mysql.server_config.file }}
|
||||
- template: jinja
|
||||
- source: salt://mysql/files/server.cnf
|
||||
{% if os_family in ['Debian', 'Gentoo', 'RedHat'] %}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 644
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if "library_config" in mysql %}
|
||||
mysql_library_config:
|
||||
file.managed:
|
||||
- name: {{ mysql.config_directory + mysql.library_config.file }}
|
||||
- template: jinja
|
||||
- source: salt://mysql/files/client.cnf
|
||||
{% if os_family in ['Debian', 'Gentoo', 'RedHat'] %}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 644
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if "clients_config" in mysql %}
|
||||
mysql_clients_config:
|
||||
file.managed:
|
||||
- name: {{ mysql.config_directory + mysql.clients_config.file }}
|
||||
- template: jinja
|
||||
- source: salt://mysql/files/mysql-clients.cnf
|
||||
{% if os_family in ['Debian', 'Gentoo', 'RedHat'] %}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 644
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
mysql_config:
|
||||
file.managed:
|
||||
- name: {{ mysql.config.file }}
|
||||
- template: jinja
|
||||
{% if "config_directory" in mysql %}
|
||||
- source: salt://mysql/files/my-include.cnf
|
||||
{% else %}
|
||||
- source: salt://mysql/files/my.cnf
|
||||
{% endif %}
|
||||
{% if os_family in ['Debian', 'Gentoo', 'RedHat'] %}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 644
|
||||
{% endif %}
|
|
@ -98,8 +98,11 @@ CentOS:
|
|||
service: mysqld
|
||||
python: MySQL-python
|
||||
dev: mysql-devel
|
||||
config_directory: /etc/my.cnf.d/
|
||||
config:
|
||||
file: /etc/my.cnf
|
||||
server_config:
|
||||
file: server.cnf
|
||||
sections:
|
||||
mysqld_safe:
|
||||
log_error: /var/log/mysqld.log
|
||||
|
|
40
mysql/files/client.cnf
Normal file
40
mysql/files/client.cnf
Normal file
|
@ -0,0 +1,40 @@
|
|||
# DO NOT CHANGE THIS FILE!
|
||||
# This config is generated by SALTSTACK
|
||||
# and all change will be overrided on next salt call
|
||||
{#-
|
||||
===== FETCH DATA =====
|
||||
-#}
|
||||
{%- from "mysql/defaults.yaml" import rawmap with context -%}
|
||||
{%- from "mysql/supported_sections.yaml" import supported_sections with context -%}
|
||||
{%- set datamap = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:library:lookup')) -%}
|
||||
{#-
|
||||
===== COMBINE DATA =====
|
||||
-#}
|
||||
{%- set goodParamList = datamap.library_config.sections -%}
|
||||
{%- for section_name in supported_sections -%}
|
||||
{%- set sectdict = datamap.library_config.sections[section_name] | default({}) -%}
|
||||
{%- for mparam, mvalue in salt['pillar.get']('mysql:library:'+section_name, {}).items() -%}
|
||||
{%- set mparamUnderscore = mparam | replace('-','_') -%}
|
||||
{%- do sectdict.update({mparamUnderscore:mvalue}) -%}
|
||||
{%- endfor -%}
|
||||
{%- do goodParamList.update({section_name:sectdict}) -%}
|
||||
{%- endfor -%}
|
||||
{#-
|
||||
===== PRINT DATA =====
|
||||
-#}
|
||||
{%- for sname,sdata in goodParamList.items() -%}
|
||||
{%- if sdata %}
|
||||
|
||||
[{{ sname }}]
|
||||
{%- for mparam, mvalue in sdata.items()|default([])|sort -%}
|
||||
{%- set indents = 40 - mparam|count %}
|
||||
{% if mvalue == "noarg_present" -%}
|
||||
{{ mparam }}
|
||||
{%- else -%}
|
||||
{{ mparam }}{{ '='|indent(indents, true) }} {{ mvalue }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- endfor %}
|
||||
|
||||
{{ datamap.library_config.append | default('') }}
|
47
mysql/files/my-include.cnf
Normal file
47
mysql/files/my-include.cnf
Normal file
|
@ -0,0 +1,47 @@
|
|||
# DO NOT CHANGE THIS FILE!
|
||||
# This config is generated by SALTSTACK
|
||||
# and all change will be overrided on next salt call
|
||||
{#-
|
||||
===== FETCH DATA =====
|
||||
-#}
|
||||
{%- from "mysql/defaults.yaml" import rawmap with context -%}
|
||||
{%- from "mysql/supported_sections.yaml" import supported_sections with context -%}
|
||||
{%- set datamap = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:global:lookup')) -%}
|
||||
{#-
|
||||
===== COMBINE DATA =====
|
||||
-#}
|
||||
{%- if "sections" in datamap.config -%}
|
||||
{%- set goodParamList = datamap.config.sections -%}
|
||||
{%- for section_name in supported_sections -%}
|
||||
{%- set sectdict = datamap.config.sections[section_name] | default({}) -%}
|
||||
{%- for mparam, mvalue in salt['pillar.get']('mysql:global:'+section_name, {}).items() -%}
|
||||
{%- set mparamUnderscore = mparam | replace('-','_') -%}
|
||||
{%- do sectdict.update({mparamUnderscore:mvalue}) -%}
|
||||
{%- endfor -%}
|
||||
{%- do goodParamList.update({section_name:sectdict}) -%}
|
||||
{%- endfor -%}
|
||||
{%- else -%}
|
||||
{%- set goodParamList = {} -%}
|
||||
{%- endif -%}
|
||||
{#-
|
||||
===== PRINT DATA =====
|
||||
-#}
|
||||
{%- for sname,sdata in goodParamList.items() -%}
|
||||
{%- if sdata %}
|
||||
|
||||
[{{ sname }}]
|
||||
{%- for mparam, mvalue in sdata.items()|default([])|sort -%}
|
||||
{%- set indents = 40 - mparam|count %}
|
||||
{% if mvalue == "noarg_present" -%}
|
||||
{{ mparam }}
|
||||
{%- else -%}
|
||||
{{ mparam }}{{ '='|indent(indents, true) }} {{ mvalue }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- endfor %}
|
||||
|
||||
#
|
||||
# include all files from the config directory
|
||||
#
|
||||
!includedir {{ datamap.config_directory }}
|
40
mysql/files/mysql-clients.cnf
Normal file
40
mysql/files/mysql-clients.cnf
Normal file
|
@ -0,0 +1,40 @@
|
|||
# DO NOT CHANGE THIS FILE!
|
||||
# This config is generated by SALTSTACK
|
||||
# and all change will be overrided on next salt call
|
||||
{#-
|
||||
===== FETCH DATA =====
|
||||
-#}
|
||||
{%- from "mysql/defaults.yaml" import rawmap with context -%}
|
||||
{%- from "mysql/supported_sections.yaml" import supported_sections with context -%}
|
||||
{%- set datamap = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:clients:lookup')) -%}
|
||||
{#-
|
||||
===== COMBINE DATA =====
|
||||
-#}
|
||||
{%- set goodParamList = datamap.clients_config.sections -%}
|
||||
{%- for section_name in supported_sections -%}
|
||||
{%- set sectdict = datamap.clients_config.sections[section_name] | default({}) -%}
|
||||
{%- for mparam, mvalue in salt['pillar.get']('mysql:clients:'+section_name, {}).items() -%}
|
||||
{%- set mparamUnderscore = mparam | replace('-','_') -%}
|
||||
{%- do sectdict.update({mparamUnderscore:mvalue}) -%}
|
||||
{%- endfor -%}
|
||||
{%- do goodParamList.update({section_name:sectdict}) -%}
|
||||
{%- endfor -%}
|
||||
{#-
|
||||
===== PRINT DATA =====
|
||||
-#}
|
||||
{%- for sname,sdata in goodParamList.items() -%}
|
||||
{%- if sdata %}
|
||||
|
||||
[{{ sname }}]
|
||||
{%- for mparam, mvalue in sdata.items()|default([])|sort -%}
|
||||
{%- set indents = 40 - mparam|count %}
|
||||
{% if mvalue == "noarg_present" -%}
|
||||
{{ mparam }}
|
||||
{%- else -%}
|
||||
{{ mparam }}{{ '='|indent(indents, true) }} {{ mvalue }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- endfor %}
|
||||
|
||||
{{ datamap.clients_config.append | default('') }}
|
40
mysql/files/server.cnf
Normal file
40
mysql/files/server.cnf
Normal file
|
@ -0,0 +1,40 @@
|
|||
# DO NOT CHANGE THIS FILE!
|
||||
# This config is generated by SALTSTACK
|
||||
# and all change will be overrided on next salt call
|
||||
{#-
|
||||
===== FETCH DATA =====
|
||||
-#}
|
||||
{%- from "mysql/defaults.yaml" import rawmap with context -%}
|
||||
{%- from "mysql/supported_sections.yaml" import supported_sections with context -%}
|
||||
{%- set datamap = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:server:lookup')) -%}
|
||||
{#-
|
||||
===== COMBINE DATA =====
|
||||
-#}
|
||||
{%- set goodParamList = datamap.server_config.sections -%}
|
||||
{%- for section_name in supported_sections -%}
|
||||
{%- set sectdict = datamap.server_config.sections[section_name] | default({}) -%}
|
||||
{%- for mparam, mvalue in salt['pillar.get']('mysql:server:'+section_name, {}).items() -%}
|
||||
{%- set mparamUnderscore = mparam | replace('-','_') -%}
|
||||
{%- do sectdict.update({mparamUnderscore:mvalue}) -%}
|
||||
{%- endfor -%}
|
||||
{%- do goodParamList.update({section_name:sectdict}) -%}
|
||||
{%- endfor -%}
|
||||
{#-
|
||||
===== PRINT DATA =====
|
||||
-#}
|
||||
{%- for sname,sdata in goodParamList.items() -%}
|
||||
{%- if sdata %}
|
||||
|
||||
[{{ sname }}]
|
||||
{%- for mparam, mvalue in sdata.items()|default([])|sort -%}
|
||||
{%- set indents = 40 - mparam|count %}
|
||||
{% if mvalue == "noarg_present" -%}
|
||||
{{ mparam }}
|
||||
{%- else -%}
|
||||
{{ mparam }}{{ '='|indent(indents, true) }} {{ mvalue }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- endfor %}
|
||||
|
||||
{{ datamap.server_config.append | default('') }}
|
|
@ -1,3 +1,7 @@
|
|||
include:
|
||||
- mysql.config
|
||||
- mysql.python
|
||||
|
||||
{% from "mysql/defaults.yaml" import rawmap with context %}
|
||||
{%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:lookup')) %}
|
||||
|
||||
|
@ -32,9 +36,6 @@ mysql_root_password:
|
|||
- require:
|
||||
- service: mysqld
|
||||
|
||||
include:
|
||||
- mysql.python
|
||||
|
||||
{% for host in ['localhost', 'localhost.localdomain', salt['grains.get']('fqdn')] %}
|
||||
mysql_delete_anonymous_user_{{ host }}:
|
||||
mysql_user:
|
||||
|
@ -83,19 +84,10 @@ mysqld:
|
|||
- enable: True
|
||||
- watch:
|
||||
- pkg: mysqld
|
||||
|
||||
mysql_config:
|
||||
file.managed:
|
||||
- name: {{ mysql.config.file }}
|
||||
- template: jinja
|
||||
- source: salt://mysql/files/my.cnf
|
||||
- watch_in:
|
||||
- service: mysqld
|
||||
{% if os_family in ['Debian', 'Gentoo', 'RedHat'] %}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 644
|
||||
{% endif %}
|
||||
- file: mysql_config
|
||||
{% if "config_directory" in mysql and "server_config" in mysql %}
|
||||
- file: mysql_server_config
|
||||
{% endif %}
|
||||
|
||||
# official oracle mysql repo
|
||||
# creates this file, that rewrites /etc/mysql/my.cnf setting
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
# vim
|
||||
{% load_yaml as supported_sections %}
|
||||
- client-server
|
||||
- client
|
||||
- client-mariadb
|
||||
- mariadb
|
||||
- mysql
|
||||
- mysqldump
|
||||
- mysqld_safe
|
||||
|
@ -9,9 +12,14 @@
|
|||
- mysqlcheck
|
||||
- mysqlimport
|
||||
- mysqlshow
|
||||
- mysql_upgrade
|
||||
- mysqlbinlog
|
||||
- mysqlslap
|
||||
- myisampack
|
||||
- myisamchk
|
||||
- isamchk
|
||||
- mysqld
|
||||
- mysqld_multi
|
||||
- server
|
||||
- xtrabackup
|
||||
{% endload %}
|
||||
|
|
|
@ -1,4 +1,18 @@
|
|||
mysql:
|
||||
global:
|
||||
client-server:
|
||||
default_character_set: utf8
|
||||
|
||||
clients:
|
||||
mysql:
|
||||
default_character_set: utf8
|
||||
mysqldump:
|
||||
default_character_set: utf8
|
||||
|
||||
library:
|
||||
client:
|
||||
default_character_set: utf8
|
||||
|
||||
server:
|
||||
# Use this account for database admin (defaults to root)
|
||||
root_user: 'admin'
|
||||
|
|
Loading…
Add table
Reference in a new issue