Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking Changes

* **role:mariadb_server**: MariaDB may open at least 65536 files instead of 32768 (`mariadb_server__service_limit_nofile`), enough for 16 table cache instances, and a lower value no longer takes effect; a higher limit that the MariaDB package or systemd set is kept. The next run restarts MariaDB.
* **role:fail2ban**: On hosts with Apache logs below `/var/log/httpd`, the role enables the Apache jails fail2ban ships (`apache-auth`, `apache-fakegooglebot`, `apache-modsecurity`, `apache-nohome`, `apache-noscript`, `apache-overflows`, `php-url-fopen`), unless `apache_httpd__mod_remoteip_internal_proxy` lists a proxy. On a host behind a reverse proxy that Apache logs as the client, such as LibreNMS behind a proxy, set `fail2ban__jails_apache_enabled: false`, otherwise the jails ban the proxy.
* **role:fail2ban**: The sshd jail also bans clients that connect without trying to log in, such as scanners (filter mode `aggressive`). Set `fail2ban__jail_sshd_mode: 'normal'` to keep the previous behaviour.
* **role:repo_baseos**: The Rocky Linux `security` repository downloads from `dl.rockylinux.org` instead of a mirror from the mirrorlist, so hot-fixes reach all hosts at the same time instead of whenever their mirror has synced. Hosts behind an egress filter need HTTPS access to `dl.rockylinux.org`.
Expand Down Expand Up @@ -88,6 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* **role:mariadb_server**: `table_open_cache_instances` is configurable with `mariadb_server__cnf_table_open_cache_instances__host_var` / `mariadb_server__cnf_table_open_cache_instances__group_var`.
* **tool:lfops**: `tools/lfops` assembles and starts an `ansible-navigator run` in a terminal UI: pick the playbook, its tags (read from the role READMEs), the inventories below `$LF_GITLAB` and the hosts, groups or a glob as limit. The entries used last are listed first, further arguments such as `--check --diff` are passed on to ansible-navigator. With `eval "$(command lfops --shell-init)"` in `~/.bashrc`, the command lands on the Bash prompt and in the shell history instead of running right away.
* **playbook:fail2ban**: Deploys the Linuxfabrik repository on RHEL 8 to 10, which serves fail2ban built from the latest upstream release, so the filters recognize attacks the EPEL build lets through, such as the path traversal attempts behind `AH10244: invalid URI path`. Skip it with `fail2ban__skip_repo_linuxfabrik`.
* **role:php**: `php__opcache_blacklist__host_var` / `php__opcache_blacklist__group_var` exclude files from OPcache, and the role creates the blacklist file that `opcache.blacklist_filename` already pointed to.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mariadb_server__cnf_innodb_snapshot_isolation__group_var: 'ON'
# With it, the role removes the proxies_priv entries that converge.yml seeds.
mariadb_server__cnf_skip_name_resolve__group_var: 'ON'
mariadb_server__cnf_table_open_cache_instances__group_var: 16

# The dump user enables the daily mariadb-dump, which needs mydumper from the mydumper repository.
mariadb_server__admin_user:
Expand Down
6 changes: 3 additions & 3 deletions extensions/molecule/mariadb_server/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@
# ask the running server, the cnf file alone proves nothing. innodb_linux_aio is the role
# default per OS family, and innodb_use_native_aio shows that InnoDB did not fall back to
# simulated AIO.
- name: 'mariadb --execute="SELECT @@table_definition_cache, @@innodb_linux_aio, @@innodb_use_native_aio, @@innodb_snapshot_isolation, @@skip_name_resolve"'
ansible.builtin.command: 'mariadb --user=mariadb-admin --password=linuxfabrik --host=127.0.0.1 --batch --skip-column-names --execute="SELECT @@table_definition_cache, @@innodb_linux_aio, @@innodb_use_native_aio, @@innodb_snapshot_isolation, @@skip_name_resolve"'
- name: 'mariadb --execute="SELECT @@table_definition_cache, @@innodb_linux_aio, @@innodb_use_native_aio, @@innodb_snapshot_isolation, @@skip_name_resolve, @@table_open_cache_instances"'
ansible.builtin.command: 'mariadb --user=mariadb-admin --password=linuxfabrik --host=127.0.0.1 --batch --skip-column-names --execute="SELECT @@table_definition_cache, @@innodb_linux_aio, @@innodb_use_native_aio, @@innodb_snapshot_isolation, @@skip_name_resolve, @@table_open_cache_instances"'
register: '__molecule__mariadb_variables_result'
changed_when: false

- name: 'Assert that the server uses the configured values'
ansible.builtin.assert:
that: '__molecule__mariadb_variables_result["stdout"].split() == ["600", ("aio" if ansible_facts["os_family"] == "RedHat" else "auto"), "1", "1", "1"]'
that: '__molecule__mariadb_variables_result["stdout"].split() == ["600", ("aio" if ansible_facts["os_family"] == "RedHat" else "auto"), "1", "1", "1", "16"]'
fail_msg: '{{ __molecule__mariadb_variables_result["stdout"] }}'

# With skip_name_resolve, MariaDB warns about every grant bound to a host name whenever it
Expand Down
14 changes: 12 additions & 2 deletions roles/mariadb_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ mariadb_server__dump_user:

* Systemd: Resource limit directive for the number of file descriptors.
* Type: Number.
* Default: `32768`
* Default: `65536`
* Deviates from the upstream default `32768`: MariaDB needs `table_open_cache` times `table_open_cache_instances` times 2 file handles plus `max_connections`, and 32768 leaves room for only 8 of the 16 table cache instances a host with many CPUs can use.
* The role sets the highest of this value, `65536` and the limit `mariadb.service` gets without the role (the `LimitNOFILE` of the unit file the package ships, else the default of systemd), and leaves `LimitNOFILE` out of its drop-in when that limit is already the highest, so it never lowers the limit.

`mariadb_server__service_timeout_start_sec`

Expand Down Expand Up @@ -450,7 +452,7 @@ mariadb_server__roles__host_var:
- '*.*:SELECT'
state: 'present'
mariadb_server__service_limit_memlock: 524288
mariadb_server__service_limit_nofile: 32768
mariadb_server__service_limit_nofile: 131072
mariadb_server__service_timeout_start_sec: '15min'
mariadb_server__service_timeout_stop_sec: '15min'
mariadb_server__skip_sys_schema: false
Expand Down Expand Up @@ -935,6 +937,13 @@ Variables for `z00-linuxfabrik.cnf` directives and their default values, defined
* Type: Number.
* Default: `2000`

`mariadb_server__cnf_table_open_cache_instances__group_var` / `mariadb_server__cnf_table_open_cache_instances__host_var`

* [mariadb.com](https://mariadb.com/docs/server/server-management/variables-and-modes/server-system-variables#table_open_cache_instances)
* Type: Number.
* Default: `8`
* MariaDB lowers the value at startup to what the open files limit allows, without logging it: each instance needs `table_open_cache` times 2 file handles on top of `max_connections`. With `table_open_cache = 2000`, the open files limit the role sets fits 16 instances; for more, raise `mariadb_server__service_limit_nofile`.

`mariadb_server__cnf_tls_version__group_var` / `mariadb_server__cnf_tls_version__host_var`

* [mariadb.com](https://mariadb.com/docs/server/server-management/variables-and-modes/server-system-variables#tls_version)
Expand Down Expand Up @@ -1035,6 +1044,7 @@ mariadb_server__cnf_sort_buffer_size__host_var: '2M'
mariadb_server__cnf_sql_mode__host_var: 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
mariadb_server__cnf_table_definition_cache__host_var: 400
mariadb_server__cnf_table_open_cache__host_var: 3000
mariadb_server__cnf_table_open_cache_instances__host_var: 16
mariadb_server__cnf_tls_version__host_var: 'TLSv1.2,TLSv1.3'
mariadb_server__cnf_tmp_table_size__host_var: '16M'
mariadb_server__cnf_tmpdir__host_var: '/data/tmpdir'
Expand Down
12 changes: 11 additions & 1 deletion roles/mariadb_server/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,16 @@ mariadb_server__cnf_table_open_cache__combined_var: '{{
mariadb_server__cnf_table_open_cache__dependent_var: ''
mariadb_server__cnf_table_open_cache__group_var: ''
mariadb_server__cnf_table_open_cache__host_var: ''
mariadb_server__cnf_table_open_cache_instances__combined_var: '{{
mariadb_server__cnf_table_open_cache_instances__host_var if (mariadb_server__cnf_table_open_cache_instances__host_var | string | length) else
mariadb_server__cnf_table_open_cache_instances__group_var if (mariadb_server__cnf_table_open_cache_instances__group_var | string | length) else
mariadb_server__cnf_table_open_cache_instances__dependent_var if (mariadb_server__cnf_table_open_cache_instances__dependent_var | string | length) else
mariadb_server__cnf_table_open_cache_instances__role_var
}}'

mariadb_server__cnf_table_open_cache_instances__dependent_var: ''
mariadb_server__cnf_table_open_cache_instances__group_var: ''
mariadb_server__cnf_table_open_cache_instances__host_var: ''
mariadb_server__cnf_tls_version__combined_var: '{{
mariadb_server__cnf_tls_version__host_var if (mariadb_server__cnf_tls_version__host_var | string | length) else
mariadb_server__cnf_tls_version__group_var if (mariadb_server__cnf_tls_version__group_var | string | length) else
Expand Down Expand Up @@ -1026,7 +1036,7 @@ mariadb_server__roles__role_var: []
mariadb_server__run_galera_new_cluster: false

mariadb_server__service_limit_memlock: 524288
mariadb_server__service_limit_nofile: 32768
mariadb_server__service_limit_nofile: 65536 # upstream default: 32768 (LimitNOFILE in mariadb.service)
mariadb_server__service_timeout_start_sec: '15min'
mariadb_server__service_timeout_stop_sec: '15min'

Expand Down
33 changes: 33 additions & 0 deletions roles/mariadb_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,39 @@
register: 'mariadb_server__socket_selinux_workaround_result'
notify: 'mariadb_server: systemctl restart mariadb'

# The drop-in never lowers the open files limit below what mariadb.service gets without it:
# the LimitNOFILE of the unit file the package ships, else the default of the service manager.
# A value of "soft:hard" counts by its hard limit.
- name: 'systemctl show mariadb.service --property=FragmentPath --value'
ansible.builtin.command: 'systemctl show mariadb.service --property=FragmentPath --value' # noqa command-instead-of-module
register: '__mariadb_server__unit_fragment_path_result'
changed_when: false
check_mode: false

- name: 'cat {{ __mariadb_server__unit_fragment_path_result["stdout"] }}'
ansible.builtin.slurp:
src: '{{ __mariadb_server__unit_fragment_path_result["stdout"] }}'
register: '__mariadb_server__unit_fragment_result'
when:
- '__mariadb_server__unit_fragment_path_result["stdout"] | length > 0'

- name: 'systemctl show --property=DefaultLimitNOFILE --value'
ansible.builtin.command: 'systemctl show --property=DefaultLimitNOFILE --value' # noqa command-instead-of-module
register: '__mariadb_server__default_limit_nofile_result'
changed_when: false
check_mode: false

- name: 'Determine the open files limit mariadb.service gets without the role'
ansible.builtin.set_fact:
__mariadb_server__service_limit_nofile_os: '{{
(__mariadb_server__unit_fragment_result["content"] | d("") | b64decode)
| regex_findall("(?m)^\s*LimitNOFILE\s*=\s*(\S+)")
| last
| d(__mariadb_server__default_limit_nofile_result["stdout"])
| split(":")
| last
}}'

- name: 'Deploy /etc/systemd/system/mariadb.service.d/z00-linuxfabrik.conf'
ansible.builtin.template:
backup: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026110601
# 2026111901
# 10.11

[client]
Expand Down Expand Up @@ -117,6 +117,7 @@ ssl_key = {{ mariadb_server__cnf_ssl_key_
{% endif %}
table_definition_cache = {{ mariadb_server__cnf_table_definition_cache__combined_var }}
table_open_cache = {{ mariadb_server__cnf_table_open_cache__combined_var }}
table_open_cache_instances = {{ mariadb_server__cnf_table_open_cache_instances__combined_var }}
tls_version = {{ mariadb_server__cnf_tls_version__combined_var }}
tmp_table_size = {{ mariadb_server__cnf_tmp_table_size__combined_var }}
{% if mariadb_server__cnf_tmpdir__combined_var is defined and mariadb_server__cnf_tmpdir__combined_var | length %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026110601
# 2026111901
# 10.6

[client]
Expand Down Expand Up @@ -114,6 +114,7 @@ ssl_key = {{ mariadb_server__cnf_ssl_key__combined_var }}
{% endif %}
table_definition_cache = {{ mariadb_server__cnf_table_definition_cache__combined_var }}
table_open_cache = {{ mariadb_server__cnf_table_open_cache__combined_var }}
table_open_cache_instances = {{ mariadb_server__cnf_table_open_cache_instances__combined_var }}
tls_version = {{ mariadb_server__cnf_tls_version__combined_var }}
tmp_table_size = {{ mariadb_server__cnf_tmp_table_size__combined_var }}
{% if mariadb_server__cnf_tmpdir__combined_var is defined and mariadb_server__cnf_tmpdir__combined_var | length %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026110601
# 2026111901
# 11.4

[client]
Expand Down Expand Up @@ -107,6 +107,7 @@ ssl_cert = {{ mariadb_server__cnf_ssl_cert
ssl_key = {{ mariadb_server__cnf_ssl_key__combined_var }}
table_definition_cache = {{ mariadb_server__cnf_table_definition_cache__combined_var }}
table_open_cache = {{ mariadb_server__cnf_table_open_cache__combined_var }}
table_open_cache_instances = {{ mariadb_server__cnf_table_open_cache_instances__combined_var }}
tls_version = {{ mariadb_server__cnf_tls_version__combined_var }}
tmp_table_size = {{ mariadb_server__cnf_tmp_table_size__combined_var }}
{% if mariadb_server__cnf_tmpdir__combined_var is defined and mariadb_server__cnf_tmpdir__combined_var | length %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026110601
# 2026111901
# 11.8

[client]
Expand Down Expand Up @@ -107,6 +107,7 @@ ssl_cert = {{ mariadb_server__cnf_ssl_cert
ssl_key = {{ mariadb_server__cnf_ssl_key__combined_var }}
table_definition_cache = {{ mariadb_server__cnf_table_definition_cache__combined_var }}
table_open_cache = {{ mariadb_server__cnf_table_open_cache__combined_var }}
table_open_cache_instances = {{ mariadb_server__cnf_table_open_cache_instances__combined_var }}
tls_version = {{ mariadb_server__cnf_tls_version__combined_var }}
tmp_table_size = {{ mariadb_server__cnf_tmp_table_size__combined_var }}
{% if mariadb_server__cnf_tmpdir__combined_var is defined and mariadb_server__cnf_tmpdir__combined_var | length %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2025010801
# 2026111901

[Service]

Expand All @@ -10,7 +10,14 @@
TimeoutStartSec={{ mariadb_server__service_timeout_start_sec }}
TimeoutStopSec={{ mariadb_server__service_timeout_stop_sec }}

{# Never below 65536, which 16 table cache instances need, and never below what the unit gets
without this drop-in. Where that is already the highest, the line is left out. #}
{% set __os = (__mariadb_server__service_limit_nofile_os | string) or '0' %}
{% set __limits = [mariadb_server__service_limit_nofile | string, '65536', __os] %}
{% set __nofile = 'infinity' if 'infinity' in __limits else __limits | map('int') | max | string %}
{% if __nofile != __os %}
# Number of files limit. previously [mysqld_safe] open-files-limit
LimitNOFILE={{ mariadb_server__service_limit_nofile }}
LimitNOFILE={{ __nofile }}
{% endif %}
# For liburing and io_uring_setup()
LimitMEMLOCK={{ mariadb_server__service_limit_memlock }}
1 change: 1 addition & 0 deletions roles/mariadb_server/vars/10.11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ mariadb_server__cnf_ssl_cert__role_var: ''
mariadb_server__cnf_ssl_key__role_var: ''
mariadb_server__cnf_table_definition_cache__role_var: 600 # upstream default: 400
mariadb_server__cnf_table_open_cache__role_var: '2000'
mariadb_server__cnf_table_open_cache_instances__role_var: 8
mariadb_server__cnf_tls_version__role_var: 'TLSv1.2,TLSv1.3'
mariadb_server__cnf_tmp_table_size__role_var: '16M'
mariadb_server__cnf_tmpdir__role_var: ''
Expand Down
1 change: 1 addition & 0 deletions roles/mariadb_server/vars/10.6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mariadb_server__cnf_ssl_cert__role_var: ''
mariadb_server__cnf_ssl_key__role_var: ''
mariadb_server__cnf_table_definition_cache__role_var: 600 # upstream default: 400
mariadb_server__cnf_table_open_cache__role_var: '2000'
mariadb_server__cnf_table_open_cache_instances__role_var: 8
mariadb_server__cnf_tls_version__role_var: 'TLSv1.2,TLSv1.3'
mariadb_server__cnf_tmp_table_size__role_var: '16M'
mariadb_server__cnf_tmpdir__role_var: ''
Expand Down
1 change: 1 addition & 0 deletions roles/mariadb_server/vars/11.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ mariadb_server__cnf_ssl_cert__role_var: ''
mariadb_server__cnf_ssl_key__role_var: ''
mariadb_server__cnf_table_definition_cache__role_var: 600 # upstream default: 400
mariadb_server__cnf_table_open_cache__role_var: '2000'
mariadb_server__cnf_table_open_cache_instances__role_var: 8
mariadb_server__cnf_tls_version__role_var: 'TLSv1.2,TLSv1.3'
mariadb_server__cnf_tmp_table_size__role_var: '16M'
mariadb_server__cnf_tmpdir__role_var: ''
Expand Down
1 change: 1 addition & 0 deletions roles/mariadb_server/vars/11.8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ mariadb_server__cnf_ssl_cert__role_var: ''
mariadb_server__cnf_ssl_key__role_var: ''
mariadb_server__cnf_table_definition_cache__role_var: 600 # upstream default: 400
mariadb_server__cnf_table_open_cache__role_var: '2000'
mariadb_server__cnf_table_open_cache_instances__role_var: 8
mariadb_server__cnf_tls_version__role_var: 'TLSv1.2,TLSv1.3'
mariadb_server__cnf_tmp_table_size__role_var: '16M'
mariadb_server__cnf_tmpdir__role_var: ''
Expand Down