ansible-collections / community.proxysql

ProxySQL Ansible Collection
http://galaxy.ansible.com/community/proxysql
GNU General Public License v3.0
21 stars 26 forks source link

Not all proxysql installd have a version() suffix #154

Closed glbyers closed 6 months ago

glbyers commented 8 months ago
SUMMARY

The proxysql version() suffix isn't standard, but plugins/module_utils/mysql.py expects it to exist. ie;

def _version(cursor):
    cursor.execute("select version();")
    res = cursor.fetchone()

    # 2.2.0-72-ge14accd
    # 2.3.2-percona-1.1
    raw_version = res.get('version()').split('-', 1)
    _version = raw_version[0].split('.')

    version = dict()
    version['full'] = res.get('version()')
    version['major'] = int(_version[0])
    version['minor'] = int(_version[1])
    version['release'] = int(_version[2])
    version['suffix'] = raw_version[1]

If no suffix exists, this results in an exception

ISSUE TYPE
COMPONENT NAME

plugins/module_utils/mysql.py

ANSIBLE VERSION
ansible [core 2.14.0]
  config file = /home/gbyers/work/git/a4-ansible/ansible.cfg
  configured module search path = ['/home/gbyers/work/git/a4-ansible/modules', '/home/gbyers/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/gbyers/venv/ansible2.14/lib64/python3.11/site-packages/ansible
  ansible collection location = /home/gbyers/work/git/a4-ansible/collections:/home/gbyers/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/gbyers/venv/ansible2.14/bin/ansible
  python version = 3.11.5 (main, Sep 22 2023, 15:34:29) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/home/gbyers/venv/ansible2.14/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION

# /home/xxxx/work/git/a4-ansible/collections/ansible_collections
Collection         Version
------------------ -------
community.proxysql 1.5.1  
CONFIGURATION
CALLBACKS_ENABLED(env: ANSIBLE_CALLBACKS_ENABLED) = ['default']
COLLECTIONS_PATHS(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['/home/xxxx/work/git/a4-ansible/collections', '/home/xxxx/.ansible/collections', '/usr/share/ansible/collections']
COLOR_VERBOSE(/home/xxxx/work/git/a4-ansible/ansible.cfg) = dark gray
CONFIG_FILE() = /home/xxxx/work/git/a4-ansible/ansible.cfg
DEFAULT_ACTION_PLUGIN_PATH(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['/home/xxxx/work/git/a4-ansible/plugins/action', '/usr/share/ansible/plugins/action']
DEFAULT_ASK_PASS(/home/xxxx/work/git/a4-ansible/ansible.cfg) = True
DEFAULT_BECOME(/home/xxxx/work/git/a4-ansible/ansible.cfg) = True
DEFAULT_BECOME_ASK_PASS(/home/xxxx/work/git/a4-ansible/ansible.cfg) = True
DEFAULT_BECOME_METHOD(/home/xxxx/work/git/a4-ansible/ansible.cfg) = sudo
DEFAULT_BECOME_USER(/home/xxxx/work/git/a4-ansible/ansible.cfg) = root
DEFAULT_CONNECTION_PLUGIN_PATH(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['/home/xxxx/work/git/a4-ansible/plugins/connection', '/usr/share/ansible/plugins/connection']
DEFAULT_FILTER_PLUGIN_PATH(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['/home/xxxx/work/git/a4-ansible/plugins/filter', '/usr/share/ansible/plugins/filter']
DEFAULT_LOOKUP_PLUGIN_PATH(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['/home/xxxx/work/git/a4-ansible/plugins/lookup', '/usr/share/ansible/plugins/lookup']
DEFAULT_MANAGED_STR(/home/xxxx/work/git/a4-ansible/ansible.cfg) = This file is Ansible managed from role: {{{{ ansible_role_name }}}}
DEFAULT_MODULE_PATH(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['/home/xxxx/work/git/a4-ansible/modules', '/home/xxxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
DEFAULT_ROLES_PATH(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['/home/xxxx/work/git/a4-ansible/roles', '/home/xxxx/.ansible/roles', '/usr/share/ansible/roles', '/etc/ansible/roles']
DEFAULT_STRATEGY(env: ANSIBLE_STRATEGY) = mitogen_linear
DEFAULT_STRATEGY_PLUGIN_PATH(env: ANSIBLE_STRATEGY_PLUGINS) = ['/home/xxxx/.local/share/ansible/mitogen-0.3.4.dev0/ansible_mitogen/plugins/strategy']
DEFAULT_TEST_PLUGIN_PATH(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['/home/xxxx/work/git/a4-ansible/plugins/test', '/usr/share/ansible/plugins/test']
GALAXY_ROLE_SKELETON(/home/xxxx/work/git/a4-ansible/ansible.cfg) = /home/xxxx/work/git/a4-ansible/roles/skel
GALAXY_ROLE_SKELETON_IGNORE(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['^.git$', '^.*/.git_keep$']
GALAXY_SERVER_LIST(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['galaxy', 'automation_hub']
HOST_KEY_CHECKING(/home/xxxx/work/git/a4-ansible/ansible.cfg) = False
INVENTORY_ENABLED(/home/xxxx/work/git/a4-ansible/ansible.cfg) = ['advanced_host_list', 'host_list', 'constructed', 'generator', 'ini', 'auto', 'yaml']
MAX_FILE_SIZE_FOR_DIFF(/home/xxxx/work/git/a4-ansible/ansible.cfg) = 150000
PERSISTENT_CONNECT_TIMEOUT(/home/xxxx/work/git/a4-ansible/ansible.cfg) = 30
OS / ENVIRONMENT

RHEL9

STEPS TO REPRODUCE

Install proxysql on a rhel9 (rocky9, alma9) system from the epel repo & attempt to use the community.proxysql.proxysql role to manage config.

    - hosts: servers
      tasks:
        - name: Import the proxysql role
          ansible.builtin.import_role:
            name: community.proxysql.proxysql
          tags:
            - proxysql
EXPECTED RESULTS

proxysql modules run to completion.

ACTUAL RESULTS

Using any of the modules that rely on community/proxysql/plugins/module_utils/mysql.py result in the following exception;

Traceback (most recent call last):
  File "<stdin>", line 107, in <module>
  File "<stdin>", line 99, in _ansiballz_main
  File "<stdin>", line 47, in invoke_module
  File "/usr/lib64/python3.9/runpy.py", line 225, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.proxysql.proxysql_backend_servers_payload_2f6jvovi/ansible_community.proxysql.proxysql_backend_servers_payload.zip/ansible_collections/community/proxysql/plugins/modules/proxysql_backend_servers.py", line 503, in <module>
  File "/tmp/ansible_community.proxysql.proxysql_backend_servers_payload_2f6jvovi/ansible_community.proxysql.proxysql_backend_servers_payload.zip/ansible_collections/community/proxysql/plugins/modules/proxysql_backend_servers.py", line 445, in main
  File "/tmp/ansible_community.proxysql.proxysql_backend_servers_payload_2f6jvovi/ansible_community.proxysql.proxysql_backend_servers_payload.zip/ansible_collections/community/proxysql/plugins/module_utils/mysql.py", line 124, in mysql_connect
  File "/tmp/ansible_community.proxysql.proxysql_backend_servers_payload_2f6jvovi/ansible_community.proxysql.proxysql_backend_servers_payload.zip/ansible_collections/community/proxysql/plugins/module_utils/mysql.py", line 57, in _version
IndexError: list index out of range
glbyers commented 8 months ago

Version as returned by proxysql;

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select version();
+-----------+
| version() |
+-----------+
| 2.4.8     |
+-----------+
1 row in set (0.00 sec)
Andersson007 commented 6 months ago

@glbyers thanks for reporting the issue! fyi working on it