ansible-collections / community.postgresql

Manage PostgreSQL with Ansible
https://galaxy.ansible.com/ui/repo/published/community/postgresql/
Other
111 stars 90 forks source link

postgresql_info fails on PG betas #728

Closed hunleyd closed 2 months ago

hunleyd commented 2 months ago
SUMMARY

When running postgresql_info against one of the beta releases (e.g. PG 17 beta 3), a failure is generated:

    "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 107, in <module>\n  File \"<stdin>\", line 99, in _ansiballz_main\n  File \"<stdin>\", line 48, in invoke_module\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.postgresql.postgresql_info_payload_t6kbp51d/ansible_community.postgresql.postgresql_info_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_info.py\", line 1118, in <module>\n  File \"/tmp/ansible_community.postgresql.postgresql_info_payload_t6kbp51d/ansible_community.postgresql.postgresql_info_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_info.py\", line 1114, in main\n  File \"/tmp/ansible_community.postgresql.postgresql_info_payload_t6kbp51d/ansible_community.postgresql.postgresql_info_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_info.py\", line 666, in collect\n  File \"/tmp/ansible_community.postgresql.postgresql_info_payload_t6kbp51d/ansible_community.postgresql.postgresql_info_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_info.py\", line 997, in get_pg_version\nAttributeError: 'NoneType' object has no attribute 'group'\n",

This comes from get_pg_version() which does SELECT version() and then tries to apply r"(\d+)\.(\d+)(?:\.(\d+))? to said results. Unfortunately, the query in question returns:

 PostgreSQL 17beta3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514
 (Red Hat 8.5.0-22), 64-bit

which means that

major = int(m.group(1))
minor = int(m.group(2))

fail on lines 997/998

ISSUE TYPE
COMPONENT NAME

postgresql_info

ANSIBLE VERSION
ansible [core 2.16.9]
  config file = /home/doug/.ansible.cfg
  configured module search path = ['/home/doug/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/doug/.local/share/virtualenvs/a216/lib/python3.12/site-packages/ansible
  ansible collection location = /home/doug/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/doug/.local/share/virtualenvs/a216/bin/ansible
  python version = 3.12.3 (main, Jun 14 2024, 16:43:09) [GCC 13.2.1 20240210] (/home/doug/.local/share/virtualenvs/a216/bin/python)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
# /home/doug/.ansible/collections/ansible_collections
Collection           Version
-------------------- -------
community.postgresql 3.5.0
CONFIGURATION
ANSIBLE_NOCOWS(/home/doug/.ansible.cfg) = True
CONFIG_FILE() = /home/doug/.ansible.cfg
DEFAULT_FORKS(/home/doug/.ansible.cfg) = 32
DEFAULT_GATHERING(/home/doug/.ansible.cfg) = smart
DEFAULT_INTERNAL_POLL_INTERVAL(/home/doug/.ansible.cfg) = 0.001
DEFAULT_LOAD_CALLBACK_PLUGINS(/home/doug/.ansible.cfg) = True
DEFAULT_MANAGED_STR(/home/doug/.ansible.cfg) = "$Ansible {{{{ template_path|basename + lookup('pipe', 'git log --form>
DEFAULT_PRIVATE_KEY_FILE(/home/doug/.ansible.cfg) = /home/doug/files/vagrant.key.rsa
DEFAULT_REMOTE_USER(/home/doug/.ansible.cfg) = vagrant
DEFAULT_STDOUT_CALLBACK(/home/doug/.ansible.cfg) = unixy
DEPRECATION_WARNINGS(/home/doug/.ansible.cfg) = False
DISPLAY_SKIPPED_HOSTS(/home/doug/.ansible.cfg) = False
EDITOR(env: EDITOR) = nvim
ENABLE_TASK_DEBUGGER(/home/doug/.ansible.cfg) = False
HOST_KEY_CHECKING(/home/doug/.ansible.cfg) = False
INJECT_FACTS_AS_VARS(/home/doug/.ansible.cfg) = False
INTERPRETER_PYTHON(/home/doug/.ansible.cfg) = auto_silent
PAGER(env: PAGER) = less
RETRY_FILES_ENABLED(/home/doug/.ansible.cfg) = False
USE_PERSISTENT_CONNECTIONS(/home/doug/.ansible.cfg) = True
OS / ENVIRONMENT

This was against a RHEL 8 based OS

STEPS TO REPRODUCE

Install PG 17beta3, then try to run postgresql_info against it

EXPECTED RESULTS

version properly handled

ACTUAL RESULTS
    "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 107, in <module>\n  File \"<stdin>\", line 99, in _ansiballz_main\n  File \"<stdin>\", line 48, in invoke_module\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.postgresql.postgresql_info_payload_t6kbp51d/ansible_community.postgresql.postgresql_info_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_info.py\", line 1118, in <module>\n  File \"/tmp/ansible_community.postgresql.postgresql_info_payload_t6kbp51d/ansible_community.postgresql.postgresql_info_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_info.py\", line 1114, in main\n  File \"/tmp/ansible_community.postgresql.postgresql_info_payload_t6kbp51d/ansible_community.postgresql.postgresql_info_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_info.py\", line 666, in collect\n  File \"/tmp/ansible_community.postgresql.postgresql_info_payload_t6kbp51d/ansible_community.postgresql.postgresql_info_payload.zip/ansible_collections/community/postgresql/plugins/modules/postgresql_info.py\", line 997, in get_pg_version\nAttributeError: 'NoneType' object has no attribute 'group'\n",
hunleyd commented 2 months ago

from @keithf4

was there ever any intensions of supporting beta releases? If so, I'd say maybe use current_setting('server_version_num') instead of trying to rely on parsing that out

@Andersson007 was support for beta/rc intended? any reason to not switch as suggested?

Andersson007 commented 2 months ago

from @keithf4

was there ever any intensions of supporting beta releases? If so, I'd say maybe use current_setting('server_version_num') instead of trying to rely on parsing that out

@Andersson007 was support for beta/rc intended? any reason to not switch as suggested?

@hunleyd thanks for raising the issue! As long as the suggestion preserves backwards compatibility -i.e. ret values and user playbooks will continue working w/o any change needed- I'm OK with this. Would you like to implement it yourself? If no volunteers, I can try to do it myself, no problem, but volunteers are welcome Please let me know ASAP

hunleyd commented 2 months ago

@Andersson007 would i like to? yes. will i have time to? probably not until this fri at the earliest

Andersson007 commented 2 months ago

@Andersson007 would i like to? yes. will i have time to? probably not until this fri at the earliest

@hunleyd cool, assigned the issue to you then:) Feel free to re-assign to me if the circumstances change