saltstack-formulas / mysql-formula

Install the MySQL client and/or server
http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
85 stars 369 forks source link

[BUG] mysql.client state does not work out of the box #267

Open daks opened 2 years ago

daks commented 2 years ago

Your setup

Formula commit hash / release tag

master version b9b8792a1e9422ae5c9d92636b0c1c61014f4dd0

Versions reports (master & minion)

Using Kitchen setup from the formula

Pillar / config used

No pillar (test/salt/pillar/mysql.sls empty) Kitchen.yml changed to call mysql.client state instead of the meta-state mysql


Bug details

Describe the bug

When running state mysql.client it executes mysql.config which returns an Error if no pillar is provided

                 ID: mysql_config
           Function: file.managed
               Name: /etc/mysql/my.cnf
             Result: False
            Comment: Parent directory not present
            Started: 16:18:55.037018
           Duration: 79.531 ms
            Changes:   

Steps to reproduce the bug

You can see here the code https://github.com/daks/mysql-formula/tree/bug-client and the CI pipeline https://gitlab.com/daks/mysql-formula/-/pipelines/516218792

Expected behaviour

I expect this state to at minima install client packages. I don't necesary expect it to manage configuration but if it needs to be done, it should executed without errors

Attempts to fix the bug

None at the moment. I think the bug comes from one of the "if" in the state mysql.config

Additional context

andrii-suse commented 1 year ago

fyi (not sure why) it happens at least on Debian 11, but not on openSUSE Leap. Ah, on Leap the error is shown later, when you try to use client:

mariadb -V
mariadb: Can't read dir of '/etc/my.cnf.d' (Errcode: 2 "No such file or directory")
SkypLabs commented 1 year ago

I just hit this issue and did some work investigating it. It turns out a simple workaround exists:

# Pillar data.
mysql:
  config_directory: /etc/mysql

The configuration directory is only created if the config_directory entry is present in the pillar data:

https://github.com/saltstack-formulas/mysql-formula/blob/3c0568c749a636d59f50df4f8a0f96047edb6b09/mysql/config.sls#L4-L13

The problem comes from the absence of a default value for Debian:

https://github.com/saltstack-formulas/mysql-formula/blob/3c0568c749a636d59f50df4f8a0f96047edb6b09/mysql/osmap.yaml#L4-L5

Unlike CentOS and Fedora (lines 19 and 35):

https://github.com/saltstack-formulas/mysql-formula/blob/3c0568c749a636d59f50df4f8a0f96047edb6b09/mysql/osmap.yaml#L18-L35

I have only tested this workaround on Debian 11 so far.