Search code examples
mysqlsalt-project

Create MySql grants with password using SaltStack


To create grants for the database I use the following salt module

keystone_grants:
mysql_grants.present:
  - database: keystone.*
  - grant: ALL PRIVILEGES
  - user: keystone
  - host: localhost

But it creates me this

 ID: Keystone_database
 Function: mysql_grants.present
 Result: True
 Comment: Grant ALL PRIVILEGES on keystone.* to keystone@localhost has been added
Started: 19:42:18.428882
Duration: 4.089 ms
Changes:

i.e it creates me this grant

Grant ALL PRIVILEGES on keystone.* to keystone@localhost

But I need to create this grant

GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'password';

Can someone suggest me how to add grants with password using SaltStack


Solution

  • This state is not able to set password for the permission from the specified host. See salt.states.mysql_user for further instructions.

    This sentence is written in the docs of the salt.modules.mysql_grants. They point from there to salt.states.mysql_user. Sadly this docs do not tell a lot on grants.

    This state is not able to grant permissions for the user. See salt.states.mysql_grants for further instructions.

    Maybe it is enought to just use both:

    keystone_grants:
      mysql_grants.present:
        - host: localhost
        - database: keystone.*
        - grant: ALL PRIVILEGES
        - user: keystone
        - host: localhost
    
    keystone:
      mysql_user.present:
        - host: localhost
        - password: somesecret
    

    Additionally I would recommend the mysql-formula.