saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.21k stars 5.48k forks source link

[BUG] mysql_grants.present -- Failed to execute: GRANT all privileges #60498

Open lburinov73 opened 3 years ago

lburinov73 commented 3 years ago

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

          ID: grants
    Function: mysql_grants.present
      Result: False
     Comment: Failed to execute: "GRANT all privileges ON mydb.* TO myuser@localhost"

OS Centos 8, Mysql server 8.0.25, Salt 3003.1

Setup

user:
  mysql_user.present:
    - name: myuser
    - host: localhost
    - password: T3mp_P@ssw0rd

database:
  mysql_database.present:
     - name: mydb

grants:
  mysql_grants.present:
    - grant: all privileges
    - database: mydb.*
    - user: myuser
    - host: localhost

Steps to Reproduce the behavior

salt-call --log-level=debug state.sls test

[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/mysql.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/mysql.conf
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: i-testserver
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Override  __grains__: <module 'salt.loaded.int.log_handlers.sentry_mod' from '/usr/lib/python3.6/site-packages/salt/log/handlers/sentry_mod.py'>
[DEBUG   ] Configuration file path: /etc/salt/minion
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Grains refresh requested. Refreshing grains.
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/mysql.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/mysql.conf
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Override  __utils__: <module 'salt.loaded.int.grains.zfs' from '/usr/lib/python3.6/site-packages/salt/grains/zfs.py'>
[DEBUG   ] Elapsed time getting FQDNs: 2.231961488723755 seconds
[DEBUG   ] LazyLoaded zfs.is_supported
[DEBUG   ] Determining pillar cache
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded state.sls
[DEBUG   ] LazyLoaded direct_call.execute
[DEBUG   ] LazyLoaded saltutil.is_running
[DEBUG   ] Override  __grains__: <module 'salt.loaded.int.module.grains' from '/usr/lib/python3.6/site-packages/salt/modules/grains.py'>
[DEBUG   ] LazyLoaded grains.get
[DEBUG   ] LazyLoaded config.get
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded roots.envs
[DEBUG   ] Could not LazyLoad roots.init: 'roots.init' is not available.
[DEBUG   ] Updating roots fileserver cache
[DEBUG   ] Gathering pillar data for state run
[DEBUG   ] Determining pillar cache
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Finished gathering pillar data for state run
[INFO    ] Loading fresh modules for state activity
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Could not find file 'salt://test.sls' in saltenv 'base'
[DEBUG   ] In saltenv 'base', looking at rel_path 'test/init.sls' to resolve 'salt://test/init.sls'
[DEBUG   ] In saltenv 'base', ** considering ** path '/var/cache/salt/minion/files/base/test/init.sls' to resolve 'salt://test/init.sls'
[DEBUG   ] compile template: /var/cache/salt/minion/files/base/test/init.sls
[DEBUG   ] Jinja search path: ['/var/cache/salt/minion/files/base']
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded roots.envs
[DEBUG   ] Could not LazyLoad roots.init: 'roots.init' is not available.
[PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test/init.sls' using 'jinja' renderer: 0.04067826271057129
[DEBUG   ] Rendered data from file: /var/cache/salt/minion/files/base/test/init.sls:
user:
  mysql_user.present:
    - name: myuser
    - host: localhost
    - password: T3mp_P@ssw0rd

database:
  mysql_database.present:
     - name: mydb

grants:
 mysql_grants.present:
    - grant: all privileges
    - database: mydb.*
    - user: myuser
    - host: localhost

[DEBUG   ] Results of YAML rendering: 
OrderedDict([('user', OrderedDict([('mysql_user.present', [OrderedDict([('name', 'myuser')]), OrderedDict([('host', 'localhost')]), OrderedDict([('password', 'T3mp_P@ssw0rd')])])])), ('database', OrderedDict([('mysql_database.present', [OrderedDict([('name', 'mydb')])])])), ('grants', OrderedDict([('mysql_grants.present', [OrderedDict([('grant', 'all privileges')]), OrderedDict([('database', 'mydb.*')]), OrderedDict([('user', 'myuser')]), OrderedDict([('host', 'localhost')])])]))])
[PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test/init.sls' using 'yaml' renderer: 0.0017004013061523438
[DEBUG   ] LazyLoaded config.option
[DEBUG   ] LazyLoaded mysql.user_create
[DEBUG   ] LazyLoaded mysql_user.present
[INFO    ] Running state [myuser] at time 11:13:21.163859
[INFO    ] Executing state mysql_user.present for [myuser]
[DEBUG   ] Doing query: SELECT VERSION()
[DEBUG   ] Doing query: SELECT column_name from information_schema.COLUMNS WHERE table_schema=%(schema)s and table_name=%(table)s and column_name=%(column)s args: {'schema': 'mysql', 'table': 'user', 'column': 'Password'} 
[DEBUG   ] Doing query: SELECT plugin FROM mysql.user WHERE User=%(user)s and Host=%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] ()
[DEBUG   ] Doing query: SELECT User,Host FROM mysql.user WHERE User = %(user)s AND Host = %(host)s AND authentication_string = %(password)s args: {'user': 'myuser', 'host': 'localhost', 'password': '*BC46C918B416D2AFF1D56861D07ED94B7F2C88D4'} 
[DEBUG   ] LazyLoaded test.ping
[DEBUG   ] Doing query: SELECT plugin FROM mysql.user WHERE User=%(user)s and Host=%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] ()
[DEBUG   ] Doing query: SELECT User,Host FROM mysql.user WHERE User = %(user)s AND Host = %(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] Doing query: SELECT plugin FROM mysql.user WHERE User=%(user)s and Host=%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] ()
[DEBUG   ] Doing query: SELECT User,Host FROM mysql.user WHERE User = %(user)s AND Host = %(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] Doing query: CREATE USER %(user)s@%(host)s IDENTIFIED WITH %(auth_plugin)s BY %(password)s args: {'user': 'myuser', 'host': 'localhost', 'auth_plugin': 'mysql_native_password', 'password': 'T3mp_P@ssw0rd'} 
[DEBUG   ] Doing query: SELECT plugin FROM mysql.user WHERE User=%(user)s and Host=%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] ({'plugin': 'mysql_native_password'},)
[DEBUG   ] Doing query: SELECT User,Host FROM mysql.user WHERE User = %(user)s AND Host = %(host)s AND authentication_string = %(password)s args: {'user': 'myuser', 'host': 'localhost', 'password': '*BC46C918B416D2AFF1D56861D07ED94B7F2C88D4'} 
[INFO    ] User 'myuser'@'localhost' has been created
[INFO    ] {'myuser': 'Present'}
[INFO    ] Completed state [myuser] at time 11:13:21.206092 (duration_in_ms=42.233)
[DEBUG   ] LazyLoaded mysql_database.present
[INFO    ] Running state [mydb] at time 11:13:21.207323
[INFO    ] Executing state mysql_database.present for [mydb]
[DEBUG   ] Doing query: SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME=%(dbname)s; args: {'dbname': 'mydb'} 
[DEBUG   ] Doing query: SHOW DATABASES LIKE %(dbname)s; args: {'dbname': 'mydb'} 
[DEBUG   ] Doing query: CREATE DATABASE IF NOT EXISTS `mydb`;
[INFO    ] DB 'mydb' created
[INFO    ] {'mydb': 'Present'}
[INFO    ] Completed state [mydb] at time 11:13:21.220341 (duration_in_ms=13.017)
[DEBUG   ] LazyLoaded mysql_grants.present
[INFO    ] Running state [grants] at time 11:13:21.221925
[INFO    ] Executing state mysql_grants.present for [grants]
[DEBUG   ] Grant Query generated: GRANT ALTER, ALTER ROUTINE, BACKUP_ADMIN, BINLOG_ADMIN, CONNECTION_ADMIN, CREATE, CREATE ROLE, CREATE ROUTINE, CREATE TABLESPACE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, DROP ROLE, ENCRYPTION_KEY_ADMIN, EVENT, EXECUTE, FILE, GROUP_REPLICATION_ADMIN, INDEX, INSERT, LOCK TABLES, PERSIST_RO_VARIABLES_ADMIN, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, REPLICATION_SLAVE_ADMIN, RESOURCE_GROUP_ADMIN, RESOURCE_GROUP_USER, ROLE_ADMIN, SELECT, SET_USER_ID, SHOW DATABASES, SHOW VIEW, SHUTDOWN, SUPER, SYSTEM_VARIABLES_ADMIN, TRIGGER, UPDATE, XA_RECOVER_ADMIN ON `mydb`.* TO %(user)s@%(host)s args {'user': 'myuser', 'host': 'localhost'}
[DEBUG   ] Doing query: SELECT plugin FROM mysql.user WHERE User=%(user)s and Host=%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] ({'plugin': 'mysql_native_password'},)
[DEBUG   ] Doing query: SELECT User,Host FROM mysql.user WHERE User = %(user)s AND Host = %(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] Doing query: SHOW GRANTS FOR %(user)s@%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] ['GRANT USAGE ON *.* TO `myuser`@`localhost`']
[DEBUG   ] _grant_to_tokens entry 'GRANT USAGE ON *.* TO `myuser`@`localhost`'
[DEBUG   ] grant to token '`myuser`'::'`localhost`'::'['USAGE']'::'*.*'
[DEBUG   ] _grant_to_tokens entry '{'qry': 'GRANT ALTER, ALTER ROUTINE, BACKUP_ADMIN, BINLOG_ADMIN, CONNECTION_ADMIN, CREATE, CREATE ROLE, CREATE ROUTINE, CREATE TABLESPACE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, DROP ROLE, ENCRYPTION_KEY_ADMIN, EVENT, EXECUTE, FILE, GROUP_REPLICATION_ADMIN, INDEX, INSERT, LOCK TABLES, PERSIST_RO_VARIABLES_ADMIN, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, REPLICATION_SLAVE_ADMIN, RESOURCE_GROUP_ADMIN, RESOURCE_GROUP_USER, ROLE_ADMIN, SELECT, SET_USER_ID, SHOW DATABASES, SHOW VIEW, SHUTDOWN, SUPER, SYSTEM_VARIABLES_ADMIN, TRIGGER, UPDATE, XA_RECOVER_ADMIN ON `mydb`.* TO %(user)s@%(host)s', 'args': {'user': 'myuser', 'host': 'localhost'}}'
[DEBUG   ] grant to token 'myuser'::'localhost'::'['ALTER', 'ALTER ROUTINE', 'BACKUP_ADMIN', 'BINLOG_ADMIN', 'CONNECTION_ADMIN', 'CREATE', 'CREATE ROLE', 'CREATE ROUTINE', 'CREATE TABLESPACE', 'CREATE TEMPORARY TABLES', 'CREATE USER', 'CREATE VIEW', 'DELETE', 'DROP', 'DROP ROLE', 'ENCRYPTION_KEY_ADMIN', 'EVENT', 'EXECUTE', 'FILE', 'GROUP_REPLICATION_ADMIN', 'INDEX', 'INSERT', 'LOCK TABLES', 'PERSIST_RO_VARIABLES_ADMIN', 'PROCESS', 'REFERENCES', 'RELOAD', 'REPLICATION CLIENT', 'REPLICATION SLAVE', 'REPLICATION_SLAVE_ADMIN', 'RESOURCE_GROUP_ADMIN', 'RESOURCE_GROUP_USER', 'ROLE_ADMIN', 'SELECT', 'SET_USER_ID', 'SHOW DATABASES', 'SHOW VIEW', 'SHUTDOWN', 'SUPER', 'SYSTEM_VARIABLES_ADMIN', 'TRIGGER', 'UPDATE', 'XA_RECOVER_ADMIN']'::'`mydb`.*'
[DEBUG   ] grants mismatch '{'user': '`myuser`', 'database': '*.*', 'host': '`localhost`', 'grant': ['USAGE']}'<>'{'user': 'myuser', 'host': 'localhost', 'grant': ['ALTER', 'ALTER ROUTINE', 'BACKUP_ADMIN', 'BINLOG_ADMIN', 'CONNECTION_ADMIN', 'CREATE', 'CREATE ROLE', 'CREATE ROUTINE', 'CREATE TABLESPACE', 'CREATE TEMPORARY TABLES', 'CREATE USER', 'CREATE VIEW', 'DELETE', 'DROP', 'DROP ROLE', 'ENCRYPTION_KEY_ADMIN', 'EVENT', 'EXECUTE', 'FILE', 'GROUP_REPLICATION_ADMIN', 'INDEX', 'INSERT', 'LOCK TABLES', 'PERSIST_RO_VARIABLES_ADMIN', 'PROCESS', 'REFERENCES', 'RELOAD', 'REPLICATION CLIENT', 'REPLICATION SLAVE', 'REPLICATION_SLAVE_ADMIN', 'RESOURCE_GROUP_ADMIN', 'RESOURCE_GROUP_USER', 'ROLE_ADMIN', 'SELECT', 'SET_USER_ID', 'SHOW DATABASES', 'SHOW VIEW', 'SHUTDOWN', 'SUPER', 'SYSTEM_VARIABLES_ADMIN', 'TRIGGER', 'UPDATE', 'XA_RECOVER_ADMIN'], 'database': '`mydb`.*'}'
[DEBUG   ] Grant does not exist, or is perhaps not ordered properly?
[DEBUG   ] Grant Query generated: GRANT ALL PRIVILEGES ON `mydb`.* TO %(user)s@%(host)s args {'user': 'myuser', 'host': 'localhost'}
[DEBUG   ] Doing query: GRANT ALL PRIVILEGES ON `mydb`.* TO %(user)s@%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] Grant Query generated: GRANT ALTER, ALTER ROUTINE, BACKUP_ADMIN, BINLOG_ADMIN, CONNECTION_ADMIN, CREATE, CREATE ROLE, CREATE ROUTINE, CREATE TABLESPACE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, DROP ROLE, ENCRYPTION_KEY_ADMIN, EVENT, EXECUTE, FILE, GROUP_REPLICATION_ADMIN, INDEX, INSERT, LOCK TABLES, PERSIST_RO_VARIABLES_ADMIN, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, REPLICATION_SLAVE_ADMIN, RESOURCE_GROUP_ADMIN, RESOURCE_GROUP_USER, ROLE_ADMIN, SELECT, SET_USER_ID, SHOW DATABASES, SHOW VIEW, SHUTDOWN, SUPER, SYSTEM_VARIABLES_ADMIN, TRIGGER, UPDATE, XA_RECOVER_ADMIN ON `mydb`.* TO %(user)s@%(host)s args {'user': 'myuser', 'host': 'localhost'}
[DEBUG   ] Doing query: SELECT plugin FROM mysql.user WHERE User=%(user)s and Host=%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] ({'plugin': 'mysql_native_password'},)
[DEBUG   ] Doing query: SELECT User,Host FROM mysql.user WHERE User = %(user)s AND Host = %(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] Doing query: SHOW GRANTS FOR %(user)s@%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[DEBUG   ] ['GRANT USAGE ON *.* TO `myuser`@`localhost`', 'GRANT ALL PRIVILEGES ON `mydb`.* TO `myuser`@`localhost`']
[DEBUG   ] _grant_to_tokens entry 'GRANT USAGE ON *.* TO `myuser`@`localhost`'
[DEBUG   ] grant to token '`myuser`'::'`localhost`'::'['USAGE']'::'*.*'
[DEBUG   ] _grant_to_tokens entry 'GRANT ALL PRIVILEGES ON `mydb`.* TO `myuser`@`localhost`'
[DEBUG   ] grant to token '`myuser`'::'`localhost`'::'['ALL PRIVILEGES']'::'`mydb`.*'
[DEBUG   ] _grant_to_tokens entry '{'qry': 'GRANT ALTER, ALTER ROUTINE, BACKUP_ADMIN, BINLOG_ADMIN, CONNECTION_ADMIN, CREATE, CREATE ROLE, CREATE ROUTINE, CREATE TABLESPACE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, DROP ROLE, ENCRYPTION_KEY_ADMIN, EVENT, EXECUTE, FILE, GROUP_REPLICATION_ADMIN, INDEX, INSERT, LOCK TABLES, PERSIST_RO_VARIABLES_ADMIN, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, REPLICATION_SLAVE_ADMIN, RESOURCE_GROUP_ADMIN, RESOURCE_GROUP_USER, ROLE_ADMIN, SELECT, SET_USER_ID, SHOW DATABASES, SHOW VIEW, SHUTDOWN, SUPER, SYSTEM_VARIABLES_ADMIN, TRIGGER, UPDATE, XA_RECOVER_ADMIN ON `mydb`.* TO %(user)s@%(host)s', 'args': {'user': 'myuser', 'host': 'localhost'}}'
[DEBUG   ] grant to token 'myuser'::'localhost'::'['ALTER', 'ALTER ROUTINE', 'BACKUP_ADMIN', 'BINLOG_ADMIN', 'CONNECTION_ADMIN', 'CREATE', 'CREATE ROLE', 'CREATE ROUTINE', 'CREATE TABLESPACE', 'CREATE TEMPORARY TABLES', 'CREATE USER', 'CREATE VIEW', 'DELETE', 'DROP', 'DROP ROLE', 'ENCRYPTION_KEY_ADMIN', 'EVENT', 'EXECUTE', 'FILE', 'GROUP_REPLICATION_ADMIN', 'INDEX', 'INSERT', 'LOCK TABLES', 'PERSIST_RO_VARIABLES_ADMIN', 'PROCESS', 'REFERENCES', 'RELOAD', 'REPLICATION CLIENT', 'REPLICATION SLAVE', 'REPLICATION_SLAVE_ADMIN', 'RESOURCE_GROUP_ADMIN', 'RESOURCE_GROUP_USER', 'ROLE_ADMIN', 'SELECT', 'SET_USER_ID', 'SHOW DATABASES', 'SHOW VIEW', 'SHUTDOWN', 'SUPER', 'SYSTEM_VARIABLES_ADMIN', 'TRIGGER', 'UPDATE', 'XA_RECOVER_ADMIN']'::'`mydb`.*'
[DEBUG   ] grants mismatch '{'user': '`myuser`', 'database': '*.*', 'host': '`localhost`', 'grant': ['USAGE']}'<>'{'user': 'myuser', 'host': 'localhost', 'grant': ['ALTER', 'ALTER ROUTINE', 'BACKUP_ADMIN', 'BINLOG_ADMIN', 'CONNECTION_ADMIN', 'CREATE', 'CREATE ROLE', 'CREATE ROUTINE', 'CREATE TABLESPACE', 'CREATE TEMPORARY TABLES', 'CREATE USER', 'CREATE VIEW', 'DELETE', 'DROP', 'DROP ROLE', 'ENCRYPTION_KEY_ADMIN', 'EVENT', 'EXECUTE', 'FILE', 'GROUP_REPLICATION_ADMIN', 'INDEX', 'INSERT', 'LOCK TABLES', 'PERSIST_RO_VARIABLES_ADMIN', 'PROCESS', 'REFERENCES', 'RELOAD', 'REPLICATION CLIENT', 'REPLICATION SLAVE', 'REPLICATION_SLAVE_ADMIN', 'RESOURCE_GROUP_ADMIN', 'RESOURCE_GROUP_USER', 'ROLE_ADMIN', 'SELECT', 'SET_USER_ID', 'SHOW DATABASES', 'SHOW VIEW', 'SHUTDOWN', 'SUPER', 'SYSTEM_VARIABLES_ADMIN', 'TRIGGER', 'UPDATE', 'XA_RECOVER_ADMIN'], 'database': '`mydb`.*'}'
[DEBUG   ] grants mismatch '{'user': '`myuser`', 'database': '`mydb`.*', 'host': '`localhost`', 'grant': ['ALL PRIVILEGES']}'<>'{'user': 'myuser', 'host': 'localhost', 'grant': ['ALTER', 'ALTER ROUTINE', 'BACKUP_ADMIN', 'BINLOG_ADMIN', 'CONNECTION_ADMIN', 'CREATE', 'CREATE ROLE', 'CREATE ROUTINE', 'CREATE TABLESPACE', 'CREATE TEMPORARY TABLES', 'CREATE USER', 'CREATE VIEW', 'DELETE', 'DROP', 'DROP ROLE', 'ENCRYPTION_KEY_ADMIN', 'EVENT', 'EXECUTE', 'FILE', 'GROUP_REPLICATION_ADMIN', 'INDEX', 'INSERT', 'LOCK TABLES', 'PERSIST_RO_VARIABLES_ADMIN', 'PROCESS', 'REFERENCES', 'RELOAD', 'REPLICATION CLIENT', 'REPLICATION SLAVE', 'REPLICATION_SLAVE_ADMIN', 'RESOURCE_GROUP_ADMIN', 'RESOURCE_GROUP_USER', 'ROLE_ADMIN', 'SELECT', 'SET_USER_ID', 'SHOW DATABASES', 'SHOW VIEW', 'SHUTDOWN', 'SUPER', 'SYSTEM_VARIABLES_ADMIN', 'TRIGGER', 'UPDATE', 'XA_RECOVER_ADMIN'], 'database': '`mydb`.*'}'
[DEBUG   ] Grant does not exist, or is perhaps not ordered properly?
[INFO    ] Grant 'all privileges' on 'mydb.*' for user 'myuser' has NOT been added
[ERROR   ] Failed to execute: "GRANT all privileges ON mydb.* TO myuser@localhost"
[INFO    ] Completed state [grants] at time 11:13:21.246540 (duration_in_ms=24.614)
[DEBUG   ] File /var/cache/salt/minion/accumulator/140187848584888 does not exist, no need to cleanup
[DEBUG   ] LazyLoaded state.check_result
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded highstate.output
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded nested.output
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded nested.output
local:
----------
          ID: user
    Function: mysql_user.present
        Name: myuser
      Result: True
     Comment: The user myuser@localhost has been added
     Started: 11:13:21.163859
    Duration: 42.233 ms
     Changes:   
              ----------
              myuser:
                  Present
----------
          ID: database
    Function: mysql_database.present
        Name: mydb
      Result: True
     Comment: The database mydb has been created
     Started: 11:13:21.207324
    Duration: 13.017 ms
     Changes:   
              ----------
              mydb:
                  Present
----------
          ID: grants
    Function: mysql_grants.present
      Result: False
     Comment: Failed to execute: "GRANT all privileges ON mydb.* TO myuser@localhost"
     Started: 11:13:21.221926
    Duration: 24.614 ms
     Changes:   

Summary for local
------------
Succeeded: 2 (changed=2)
Failed:    1
------------
Total states run:     3
Total run time:  79.864 ms

Versions Report

Salt Version:
          Salt: 3003.1

Dependency Versions:
          cffi: 1.11.5
      cherrypy: Not Installed
      dateutil: 2.6.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: 0.35.2
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: 1.4.6
     pycparser: 2.14
      pycrypto: Not Installed
  pycryptodome: Not Installed
        pygit2: Not Installed
        Python: 3.6.8 (default, May  8 2021, 09:11:34)
  python-gnupg: Not Installed
        PyYAML: 3.12
         PyZMQ: 19.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: centos 8 
        locale: UTF-8
       machine: x86_64
        system: Linux
       version: CentOS Stream 8 

OrangeDog commented 3 years ago

It should be mydb instead of mydb.*?

lburinov73 commented 3 years ago
 mysql_grants.present:
    - grant: all privileges
    - database: mydb
    - user: myuser
    - host: localhost

# salt-call --log-level=debug state.sls test

...

[DEBUG   ] Grant Query generated: GRANT ALL PRIVILEGES ON ``.`mydb` TO %(user)s@%(host)s args {'user': 'myuser', 'host': 'localhost'}
[DEBUG   ] Doing query: GRANT ALL PRIVILEGES ON ``.`mydb` TO %(user)s@%(host)s args: {'user': 'myuser', 'host': 'localhost'} 
[ERROR   ] MySQL Error 1102: Incorrect database name ''
[ERROR   ] Failed to execute: "GRANT all privileges ON mydb TO myuser@localhost" (MySQL Error 1102: Incorrect database name '')
[INFO    ] Completed state [grants] at time 08:57:30.667889 (duration_in_ms=10.707)
[DEBUG   ] File /var/cache/salt/minion/accumulator/139801511717520 does not exist, no need to cleanup
[DEBUG   ] LazyLoaded state.check_result
[DEBUG   ] Using pkg_resources to load entry points
[DEBUG   ] LazyLoaded highstate.output
local:
  ----------
          ID: grants
    Function: mysql_grants.present
      Result: False
     Comment: Failed to execute: "GRANT all privileges ON mydb TO myuser@localhost" (MySQL Error 1102: Incorrect database name '')
     Started: 08:57:30.657182
    Duration: 10.707 ms
OrangeDog commented 3 years ago

My mistake. Is certainly a bug.

53845714nF commented 3 years ago

I think I have a similar problem.

My State:

mailman3_db:
  mysql_database.present:
    - name: {{ pillar['SQL']['DATABASE'] }}
    - connection_host: {{ pillar['SQL']['HOST'] }}
    - connection_user: {{ pillar['SQL']['ROOT_USER'] }}
    - connection_pass: {{ pillar['SQL']['ROOT_PASSWORD'] }}
    - require:
      - pip: mysql
      - service: mariadb

mailman3_app_user:
  mysql_user.present:
    - name: {{ pillar['SQL']['APP_USER'] }}
    - password: {{ pillar['SQL']['APP_PASSWORD'] }}
    - host: '%'
    - use:
      - mysql_database: mailman3
    - require:
      - service: mariadb

user_mailman3:
  mysql_grants.present:
    - grant: all privileges
    - database: mailman3.*
    - user: {{ pillar['SQL']['APP_USER'] }}
    - require:
      - service: mariadb
      - mysql_database: {{ pillar['SQL']['DATABASE'] }}
      - mysql_user: {{ pillar['SQL']['APP_USER'] }}

user_mailman3web:
  mysql_grants.present:
    - grant: all privileges
    - database: mailman3web.*
    - user: {{ pillar['SQL']['APP_USER'] }}
    - require:
      - service: mariadb
      - mysql_database: {{ pillar['SQL']['DATABASE'] }}
      - mysql_user: {{ pillar['SQL']['APP_USER'] }}

My Error:

----------
          ID: user_mailman3
    Function: mysql_grants.present
      Result: False
     Comment: Failed to execute: "GRANT all privileges ON mailman3.* TO mailman3web@localhost" (MySQL Error 1133: Can't find any matching row in the user table)
     Started: 14:13:23.999764
    Duration: 5.069 ms
     Changes:
----------
          ID: user_mailman3web
    Function: mysql_grants.present
      Result: False
     Comment: Failed to execute: "GRANT all privileges ON mailman3web.* TO mailman3web@localhost" (MySQL Error 1133: Can't find any matching row in the user table)
     Started: 14:13:24.004971
    Duration: 4.152 ms
     Changes:

After the second attempt, the error is gone. It says that the user already exists.

----------
          ID: mailman3_db
    Function: mysql_database.present
        Name: mailman3web
      Result: True
     Comment: The database mailman3web has been created
     Started: 10:06:17.674944
    Duration: 3.913 ms
     Changes:
              ----------
              mailman3web:
                  Present
----------
          ID: mailman3_app_user
    Function: mysql_user.present
        Name: mailman3web
      Result: True
     Comment: The user mailman3web@% has been added
     Started: 10:06:17.679785
    Duration: 8.927 ms
     Changes:
              ----------
              mailman3web:
                  Present
----------