mysql_grants.present fails to execute with salt-stack

Viewed 78

I'm new with saltstack, state file that i'm using:

mybd:
  mysql_database.present

user22:
  mysql_grants.present:
    - grant: ALL PRIVILEGES
    - database: 'mybd.*'
    - user: user22
    - host: localhost
    - connection_user: root
    - connection_host: localhost
    - connection_pass: ''
    - connection_unix_socket: /tmp/mysql.sock
    - connection_charset: utf8

I am getting the following error when applying a mysql state:


      ID: mybd
Function: mysql_database.present
  Result: True
 Comment: Database mybd is already present
 Started: 09:05:09.366441
Duration: 5.835 ms
 Changes:   

      ID: user22
Function: mysql_grants.present
  Result: False
 Comment: Failed to execute: "GRANT ALL PRIVILEGES ON mybd.* TO user22@localhost"
 Started: 09:05:09.372849
Duration: 76.012 ms
 Changes:   

Summary for user

Succeeded: 1 Failed: 1

but when I go to mysql i notice that the privilege is added ! I don't know what I am doing wrong. Is there somebody who knows how to properly grant permissions to a user in mysql through salt-stack?

Salt Version:

Salt Version:
               Salt: 2015.8.0
     
    Dependency Versions:
             Jinja2: 2.7.2
           M2Crypto: 0.31.0
               Mako: Not Installed
             PyYAML: 3.11
              PyZMQ: 15.3.0
             Python: 2.7.5 (default, Nov 16 2020, 22:23:17)
               RAET: Not Installed
            Tornado: 4.2.1
                ZMQ: 4.1.4
               cffi: Not Installed
           cherrypy: Not Installed
           dateutil: Not Installed
              gitdb: Not Installed
          gitpython: Not Installed
              ioflo: Not Installed
            libnacl: Not Installed
       msgpack-pure: Not Installed
     msgpack-python: 0.6.2
       mysql-python: Not Installed
          pycparser: Not Installed
           pycrypto: 2.6.1
             pygit2: Not Installed
       python-gnupg: Not Installed
              smmap: Not Installed
            timelib: Not Installed
     
    System Versions:
               dist: centos 7.9.2009 Core
            machine: x86_64
            release: 3.10.0-1160.15.2.el7.x86_64
             system: CentOS Linux 7.9.2009 Core

mysql version:

mysql  Ver 15.1 Distrib 10.3.31-MariaDB, for Linux (x86_64) using readline 5.1
1 Answers

To know the real answer you will have to look at the minions log file. If there are any errors listed that would be why the mysql.grant_add failed.

however the way the state works is it tries to determine if the grant is already there by using the mysql module to run mysql.grant_exists and look for the grant in the database. If it doesn't find it it will run the mysql.grant_add function.

mysql.grant_add will generate the query for the grant based on the information, run the query, if either of those processes fail it will report the failure in the minion log.

After that mysql.grant_add will run mysql.grant_exists to see if the grant was added. If that doesn't return properly it will report the failure. So the question is if mysql.grant_exists can see the grant.

Also with you being on such an old version of salt but a newer version of mysql it is possible that the grant table is not returning in a way that mysql.grant_exists can detect the grant. In which case it will detect as a failure and still be able to add.

Related