vitabaks / postgresql_cluster

PostgreSQL High-Availability Cluster (based on Patroni). Automating with Ansible.
https://postgresql-cluster.org
MIT License
1.69k stars 411 forks source link

yedit.py uses deprecated yaml.load and yaml.safe_load from ruamel.yaml #496

Closed honibis closed 10 months ago

honibis commented 11 months ago

Just installed latest version with latest python and came across deprecation error. ruamel.yaml no longer exposes load and safe_load methods.

in yedit.py i commented 3 lines from line 189 to disable ruamel.yaml and it worked. I dont know about these subjects but still might be useful for people who dont use python, or you might fix it for better.

# try:
#     import     as yaml  # noqa: F401
# except ImportError:
import yaml  # noqa: F401
vitabaks commented 11 months ago

Thank you @honibis for reporting the problem.

could you point out the complete error?

If possible, try the latest available version of the yedit module - https://github.com/kwoodson/ansible-role-yedit/blob/master/library/yedit.py \ maybe we just need to update the module.

It would also be nice to report a problem in the repository of the module yedit project.

honibis commented 11 months ago

Just reported to yedit too, guess its not quite actively maintained since no-one answered the question "still maintained" asked 3 weeks ago.

This is the error output from playbook:

/tmp/ansible_yedit_payload_bb814zlq/ansible_yedit_payload.zip/ansible/modules/yedit.py", line 495
fatal: [....]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_yedit_payload_bb814zlq/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 493, in load\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1085, in load\n    error_deprecation('load', 'load', arg=_error_dep_arg, comment=_error_dep_comment)\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1039, in error_deprecation\n    raise AttributeError(s, name=None)\nAttributeError: \n\"load()\" has been removed, use\n\n  yaml = YAML(typ='rt')\n  yaml.load(...)\n\nand register any classes that you use, or check the tag attribute on the loaded data,\ninstead of file \"/tmp/ansible_yedit_payload_bb814zlq/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 493\n\n\n\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"<stdin>\", line 107, in <module>\n  File \"<stdin>\", line 99, in _ansiballz_main\n  File \"<stdin>\", line 47, in invoke_module\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_yedit_payload_bb814zlq/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 967, in <module>\n  File \"/tmp/ansible_yedit_payload_bb814zlq/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 959, in main\n  File \"/tmp/ansible_yedit_payload_bb814zlq/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 812, in run_ansible\n  File \"/tmp/ansible_yedit_payload_bb814zlq/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 495, in load\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1105, in safe_load\n    error_deprecation('safe_load', 'load', arg=\"typ='safe', pure=True\")\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1039, in error_deprecation\n    raise AttributeError(s, name=None)\nAttributeError: \n\"safe_load()\" has been removed, use\n\n  yaml = YAML(typ='safe', pure=True)\n  yaml.load(...)\n\ninstead of file \"/tmp/ansible_yedit_payload_bb814zlq/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 495\n\n\n\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: instead of file "/tmp/ansible_yedit_payload_4hu8eoir/ansible_yedit_payload.zip/ansible/modules/yedit.py", line 495
fatal: [....]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_yedit_payload_4hu8eoir/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 493, in load\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1085, in load\n    error_deprecation('load', 'load', arg=_error_dep_arg, comment=_error_dep_comment)\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1039, in error_deprecation\n    raise AttributeError(s, name=None)\nAttributeError: \n\"load()\" has been removed, use\n\n  yaml = YAML(typ='rt')\n  yaml.load(...)\n\nand register any classes that you use, or check the tag attribute on the loaded data,\ninstead of file \"/tmp/ansible_yedit_payload_4hu8eoir/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 493\n\n\n\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"<stdin>\", line 107, in <module>\n  File \"<stdin>\", line 99, in _ansiballz_main\n  File \"<stdin>\", line 47, in invoke_module\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_yedit_payload_4hu8eoir/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 967, in <module>\n  File \"/tmp/ansible_yedit_payload_4hu8eoir/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 959, in main\n  File \"/tmp/ansible_yedit_payload_4hu8eoir/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 812, in run_ansible\n  File \"/tmp/ansible_yedit_payload_4hu8eoir/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 495, in load\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1105, in safe_load\n    error_deprecation('safe_load', 'load', arg=\"typ='safe', pure=True\")\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1039, in error_deprecation\n    raise AttributeError(s, name=None)\nAttributeError: \n\"safe_load()\" has been removed, use\n\n  yaml = YAML(typ='safe', pure=True)\n  yaml.load(...)\n\ninstead of file \"/tmp/ansible_yedit_payload_4hu8eoir/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 495\n\n\n\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: instead of file "/tmp/ansible_yedit_payload_97zxk_ep/ansible_yedit_payload.zip/ansible/modules/yedit.py", line 495
fatal: [....]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_yedit_payload_97zxk_ep/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 493, in load\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1085, in load\n    error_deprecation('load', 'load', arg=_error_dep_arg, comment=_error_dep_comment)\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1039, in error_deprecation\n    raise AttributeError(s, name=None)\nAttributeError: \n\"load()\" has been removed, use\n\n  yaml = YAML(typ='rt')\n  yaml.load(...)\n\nand register any classes that you use, or check the tag attribute on the loaded data,\ninstead of file \"/tmp/ansible_yedit_payload_97zxk_ep/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 493\n\n\n\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"<stdin>\", line 107, in <module>\n  File \"<stdin>\", line 99, in _ansiballz_main\n  File \"<stdin>\", line 47, in invoke_module\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_yedit_payload_97zxk_ep/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 967, in <module>\n  File \"/tmp/ansible_yedit_payload_97zxk_ep/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 959, in main\n  File \"/tmp/ansible_yedit_payload_97zxk_ep/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 812, in run_ansible\n  File \"/tmp/ansible_yedit_payload_97zxk_ep/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 495, in load\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1105, in safe_load\n    error_deprecation('safe_load', 'load', arg=\"typ='safe', pure=True\")\n  File \"/usr/local/lib/python3.10/dist-packages/ruamel/yaml/main.py\", line 1039, in error_deprecation\n    raise AttributeError(s, name=None)\nAttributeError: \n\"safe_load()\" has been removed, use\n\n  yaml = YAML(typ='safe', pure=True)\n  yaml.load(...)\n\ninstead of file \"/tmp/ansible_yedit_payload_97zxk_ep/ansible_yedit_payload.zip/ansible/modules/yedit.py\", line 495\n\n\n\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
vitabaks commented 11 months ago

Thanks! I think it's worth waiting for a response.

https://github.com/kwoodson/ansible-role-yedit/issues/101

vitabaks commented 11 months ago

@honibis Feel free to create a PR.

honibis commented 11 months ago

@honibis Feel free to create a PR.

https://github.com/kwoodson/ansible-role-yedit/pull/102

vitabaks commented 11 months ago

I suggest leaving the issue open until the issue is fully resolved in the postgresql_cluster project.

I see the following options:

  1. Test the use of the yedit module without using ruamel.yaml (apply the fix proposed by @honibis)
  2. Update the module after fixing the problem in the ansible-role-edit project repository
  3. Refuse to use the yedit module (undesirable).
vitabaks commented 10 months ago

Fixed https://github.com/vitabaks/postgresql_cluster/pull/529