geerlingguy / ansible-role-mysql

Ansible Role - MySQL
https://galaxy.ansible.com/geerlingguy/mysql/
MIT License
1.05k stars 861 forks source link

Update configure.yml #527

Closed mkondratev closed 7 months ago

mkondratev commented 1 year ago

When:

  1. mysql_datadir is not /var/lib/mysql.
  2. mysql_slow_query_log_file and mysql_log_error use mysql_datadir

... then the deployment fails:

mysql_datadir: "/data/mysql"
mysql_slow_query_log_file: "{{ mysql_datadir }}/.mysql-slow.log"
mysql_log_error: "{{ mysql_datadir }}/.mysql-error.log"
TASK [geerlingguy.mysql : Create slow query log file (if configured).] *******************************************************************************************************
Tuesday 11 July 2023  19:58:53 +0300 (0:00:00.049)       0:02:00.408 ********** 
fatal: [vm01.vagrant.loc]: FAILED! => {"changed": true, "cmd": ["touch", "/data/mysql/.mysql-slow.log"], "delta": "0:00:00.008097", "end": "2023-07-11 16:58:53.402634", "msg": "non-zero return code", "rc": 1, "start": "2023-07-11 16:58:53.394537", "stderr": "touch: cannot touch '/data/mysql/.mysql-slow.log': No such file or directory", "stderr_lines": ["touch: cannot touch '/data/mysql/.mysql-slow.log': No such file or directory"], "stdout": "", "stdout_lines": []}
fatal: [vm02.vagrant.loc]: FAILED! => {"changed": true, "cmd": ["touch", "/data/mysql/.mysql-slow.log"], "delta": "0:00:00.005696", "end": "2023-07-11 16:58:53.405119", "msg": "non-zero return code", "rc": 1, "start": "2023-07-11 16:58:53.399423", "stderr": "touch: cannot touch '/data/mysql/.mysql-slow.log': No such file or directory", "stderr_lines": ["touch: cannot touch '/data/mysql/.mysql-slow.log': No such file or directory"], "stdout": "", "stdout_lines": []}

The directory mysql_datadir must be created before mysql_slow_query_log_file is created in it. This step works if mysql_datadir is the default, as the package creates the directory during installation.

Additionally, I suggest removing the creation of an empty file through a command and delegating this task to ansible.builtin.file.

Also, i noticed condition for step "Create error log file" wrong:

# Logging settings.
mysql_log: ""
# The following variables have a default value depending on operating system.
# mysql_log_error: /var/log/mysql/mysql.err
# mysql_syslog_tag: mysql

mysql_log and mysql_log_error are strings, while when expects bool.

  when:
    - mysql_log | default(true)
    - mysql_log_error | default(false)

checking:

- debug:
    msg:
      - "mysql_log: {{ mysql_log }} | {{ mysql_log | type_debug }}"
      - "mysql_log_error: {{ mysql_log_error }} | {{ mysql_log_error | type_debug }}"

- ansible.builtin.assert:
    that:
      - mysql_log | default(true)
      - mysql_log_error | default(false)

result:

ok: [mysql01] => {
    "msg": [
        "mysql_log:  | AnsibleUnicode",
        "mysql_log_error: /data/mysql/.mysql-error.log | str"
    ]
}

fatal: [mysql01]: FAILED! => {
    "assertion": "mysql_log | default(true)",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}
github-actions[bot] commented 9 months ago

This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

github-actions[bot] commented 7 months ago

This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.