Skip to content
Snippets Groups Projects
Verified Commit 7b055a0c authored by Chris Croome's avatar Chris Croome
Browse files

Refactor WIP

parent 45a0cf49
No related branches found
No related tags found
No related merge requests found
Pipeline #27098 failed
......@@ -16,10 +16,10 @@ mariadb_config:
state: edited
conf:
mysqld:
binlog_format: ROW
innodb_buffer_pool_instances: 1
innodb_buffer_pool_size: 1G
innodb_log_file_size: 256M
binlog_format: "ROW"
innodb_buffer_pool_instances: "1"
innodb_buffer_pool_size: "256M"
innodb_log_file_size: "64M"
join_buffer_size: "8M"
key_buffer_size: "16M"
max_allowed_packet: "64M"
......@@ -30,6 +30,7 @@ mariadb_config:
query_cache_limit: "0"
query_cache_size: "0"
query_cache_type: "0"
slow_query_log_file: "/var/log/mysql/mariadb-slow.log"
table_cache: "64"
table_open_cache: "4000"
thread_concurrency: "10"
......
......@@ -45,7 +45,7 @@
ansible.builtin.assert:
that:
- mariadb_cnf_section.value | ansible.builtin.flatten | select('regex', '-') == []
quiet: "{% if ansible_check_mode or ansible_verbosity >= 2 %}false{% else %}true{% endif %}"
quiet: "{% if ansible_verbosity == 0 %}true{% else %}false{% endif %}"
fail_msg: Although dashes or underscores can be used for MariaDB configuration variables this role only suppports the use of underscores.
loop: "{{ mariadb_cnf.conf | ansible.builtin.dict2items }}"
loop_control:
......
......@@ -23,8 +23,15 @@
mode: "{{ mariadb_cnf.mode | default('0644') }}"
owner: "{{ mariadb_cnf.owner | default('root') }}"
group: "{{ mariadb_cnf.owner | default('root') }}"
changed_when: false
register: mariadb_cnf_file_backup
when: mariadb_cnf_file_path.stat.exists | bool
- name: Debug MariaDB configuration file backup
ansible.builtin.debug:
var: mariadb_cnf_file_backup
verbosity: "{% if ansible_check_mode | bool %}2{% else %}3{% endif %}"
- name: Include the MariaDB configuration file section edited tasks
ansible.builtin.include_tasks: conf_section_edited.yml
loop: "{{ mariadb_cnf.conf | dict2items }}"
......@@ -52,6 +59,28 @@
owner: "{{ mariadb_cnf.owner | default('root') }}"
group: "{{ mariadb_cnf.owner | default('root') }}"
- name: Stat the MariaDB configuration file
ansible.builtin.stat:
path: "{{ mariadb_cnf.path }}"
get_checksum: true
checksum_algorithm: sha1
register: mariadb_cnf_file_edited
- name: Debug MariaDB configuration file
ansible.builtin.debug:
var: mariadb_cnf_file_edited
verbosity: "{% if ansible_check_mode | bool %}2{% else %}3{% endif %}"
- name: MariaDB configuration file backup absent when it is unchanged
ansible.builtin.file:
path: "{{ mariadb_cnf_file_path_backup }}"
state: absent
changed_when: false
when:
- mariadb_cnf_file_path.stat.exists | bool
- mariadb_cnf_file_backup.checksum is defined
- mariadb_cnf_file_backup.checksum == mariadb_cnf_file_edited.stat.checksum
tags:
- mariadb
- mariadb_conf
......
......@@ -18,6 +18,7 @@
- "Section: {{ mariadb_cnf_section.key }}"
- "Existing: {{ mariadb_cnf_variable_pair.key }}: {{ mariadb_cnf_file_existing_vars | community.general.json_query(mariadb_cnf_variable_jpq) }}"
- "Proposed: {{ mariadb_cnf_variable_pair.key }}: {{ mariadb_cnf_variable_pair.value }}"
- "Regex: ^[#][ ]{0,9}{{ mariadb_cnf_variable_pair.key | regex_replace('_', '[_-]') }}[ ]{0,9}[=]"
verbosity: "{% if ansible_check_mode | bool %}0{% else %}1{% endif %}"
when: mariadb_cnf_variable_pair.value != mariadb_cnf_file_existing_vars | community.general.json_query(mariadb_cnf_variable_jpq)
vars:
......@@ -27,6 +28,45 @@
loop_var: mariadb_cnf_variable_pair
label: "{{ mariadb_cnf_variable_pair.key }}"
# This is to ensure that variables are written to the same place as existing commented values
- name: Uncomment commented variables in the MariaDB configuration file that are to be edited
ansible.builtin.lineinfile:
path: "{{ mariadb_cnf.path }}"
line: "{{ mariadb_cnf_variable_pair.key }}{% if mariadb_cnf_variable_pair.value is defined %}= {{ mariadb_cnf_variable_pair.value }}{% endif %}"
regex: "{{ mariadb_cnf_variable_regex }}"
state: present
backrefs: true
mode: "{{ mariadb_cnf.mode | default('0644') }}"
owner: "{{ mariadb_cnf.owner | default('root') }}"
group: "{{ mariadb_cnf.owner | default('root') }}"
when: mariadb_cnf_variable_pair.value != mariadb_cnf_file_existing_vars | community.general.json_query(mariadb_cnf_variable_jpq)
vars:
mariadb_cnf_variable_jpq: '"{{ mariadb_cnf_section.key }}"."{{ mariadb_cnf_variable_pair.key }}"'
mariadb_cnf_variable_regex: "^[#][ ]{0,9}{{ mariadb_cnf_variable_pair.key | regex_replace('_', '[_-]') }}[ ]{0,9}[=]"
loop: "{{ mariadb_cnf_section.value | ansible.builtin.dict2items }}"
loop_control:
loop_var: mariadb_cnf_variable_pair
label: "{{ mariadb_cnf_variable_pair.key }}"
- name: MariaDB configuration file edited
community.general.ini_file:
path: "{{ mariadb_cnf.path }}"
section: "{{ mariadb_cnf_section.key }}"
option: "{{ mariadb_cnf_variable_pair.key }}"
value: "{{ mariadb_cnf_variable_pair.value }}"
allow_no_value: true
no_extra_spaces: false
mode: "{{ mariadb_cnf.mode | default('0644') }}"
owner: "{{ mariadb_cnf.owner | default('root') }}"
group: "{{ mariadb_cnf.owner | default('root') }}"
when: mariadb_cnf_variable_pair.value != mariadb_cnf_file_existing_vars | community.general.json_query(mariadb_cnf_variable_jpq)
vars:
mariadb_cnf_variable_jpq: '"{{ mariadb_cnf_section.key }}"."{{ mariadb_cnf_variable_pair.key }}"'
loop: "{{ mariadb_cnf_section.value | ansible.builtin.dict2items }}"
loop_control:
loop_var: mariadb_cnf_variable_pair
label: "{{ mariadb_cnf_variable_pair.key }} = {{ mariadb_cnf_variable_pair.value }}"
tags:
- mariadb
- mariadb_conf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment