Salt-Stack mysql_grants.present下划线通配符

时间:2015-09-02 20:33:01

标签: mysql salt-stack

我正在使用Salt来配置云服务器,但我遇到了MySQLdb产生MySQL正确权限的问题。如果我直接执行SQL,那将是:

GRANT ALL ON `install\_%`.* TO 'installer'@'localhost';

sls文件包含:

installer_local_install_grants:
  mysql_grants.present:
    - grant: all privileges
    - database: install\_%.*
    - user: installer
    - host: localhost
    - escape: False

产生此错误:

    Function: mysql_grants.present
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1560, in call
              **cdata['kwargs'])
            File "/usr/lib/python2.7/dist-packages/salt/states/mysql_grants.py", line 187, in present
              grant, database, user, host, grant_option, escape, ssl_option, **connection_args
            File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 1666, in grant_add
              _execute(cur, qry['qry'], qry['args'])
            File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 505, in _execute
              return cur.execute(qry, args)
            File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 159, in execute
              query = query % db.literal(args)
          TypeError: * wants int

在提交到MySQLdb之前,在相关行上打开salt调试是:

Doing query: GRANT ALL PRIVILEGES ON install\_%.* TO %(user)s@%(host)s args: {'host': 'localhost', 'user': 'installer'} 

所以看起来Salt正在输出正确的代码,但是MySQLdb没有正确处理查询的某些部分。查询缺少后面的标记,但我真的不确定如何获取这些。

删除转义或设置为True后,赠款如下所示:

+-----------+-----------------+------------------+
| Host      | Db              | User             |
+-----------+-----------------+------------------+
| localhost | install\\_\%    | installer        |
+-----------+-----------------+------------------+

什么时候看起来像:

+-----------+-----------------+------------------+
| Host      | Db              | User             |
+-----------+-----------------+------------------+
| localhost | install\_%      | installer        |
+-----------+-----------------+------------------+

1 个答案:

答案 0 :(得分:0)

好的,你会打开一个引用这个SO帖子的问题吗?谢谢!

https://github.com/saltstack/salt/issues/new