Skip to content

Instantly share code, notes, and snippets.

@shichi-at-nttr
Last active March 18, 2020 08:55
Show Gist options
  • Save shichi-at-nttr/ee8305dee9a791b5827526fbca53f9b9 to your computer and use it in GitHub Desktop.
Save shichi-at-nttr/ee8305dee9a791b5827526fbca53f9b9 to your computer and use it in GitHub Desktop.
Handling ProxySQL 2.0.8 with Ansible 2.9.1 - 2.9.4 will result in an error

Fixed at 2.9.6

Problems

Use proxysql_mysql_users module in ansible-playbook as such;

- name: create ProxySQL user
  proxysql_mysql_users:
    login_user: "admin"
    login_password: "adminpassword"
    username: "usernamestring"
    password: "passwordstring"
    state: present
    load_to_runtime: true
    save_to_disk: true

Causes error below:

...snip...
in check_user_privs\r\nTypeError: tuple indices must be integers or slices, not str\r\n",
...snip...

Detail Conditions

  • Ansible 2.9.1 to 2.9.3
  • ProxySQL 2.0.8
  • Python 3.6.8 on target server

Causes

For example def check_user_privs(self, cursor) in AnsiballZ_proxysql_mysql_users.py

        cursor.execute(query_string, query_data)
        check_count = cursor.fetchone()
        return (int(check_count['user_count']) > 0)

cursor has been dict type so far, but currently it is returned in tuple type. For this reason, an error occurs at check_count['user_count'].

Fixture

Change proxysql_mysql_users.py temporarily:

    cursor = None
    try:
        cursor = mysql_connect(module,
                               login_user,
                               login_password,
                               config_file,
                               cursor_class=mysql_driver.cursors.DictCursor)   <---*** HERE ***

to

    cursor = None
    try:
        cursor = mysql_connect(module,
                               login_user,
                               login_password,
                               config_file,
                               cursor_class='DictCursor')        <---*** CHANGE LIKE THIS ***

https://github.com/ansible/ansible/blob/a8b71747ae194f8eed236c491439be8edecdd9f1/lib/ansible/modules/database/proxysql/proxysql_mysql_users.py#L423

In macOS (homebrew), edit this file: /usr/local/Cellar/ansible/2.9.1/libexec/lib/python3.7/site-packages/ansible/modules/database/proxysql/proxysql_mysql_users.py

or /usr/local/Cellar/ansible/2.9.3/libexec/lib/python3.8/site-packages/ansible/modules/database/proxysql/proxysql_mysql_users.py

or /usr/local/Cellar/ansible/2.9.4/libexec/lib/python3.8/site-packages/ansible/modules/database/proxysql/proxysql_mysql_users.py

or /usr/local/Cellar/ansible/2.9.4_1/libexec/lib/python3.8/site-packages/ansible/modules/database/proxysql/proxysql_mysql_users.py

Fixed at /usr/local/Cellar/ansible/2.9.6_1/libexec/lib/python3.8/site-packages/ansible/modules/database/proxysql/proxysql_mysql_users.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment