IBM / ansible-for-i

the tool is to provide several customized modules for Ansible to manage IBM i systems.
GNU General Public License v3.0
55 stars 51 forks source link

Installation of python39 modules from the IBM i Open Source repository breaks the Power IBM i collection for Ansible #126

Closed krka01 closed 6 months ago

krka01 commented 2 years ago

We have used the Power IBM i collection for Ansible successfully with the following prerequsist python modules installed on the IBM i: python3 3.6.15-1 python3-ibm_db 2.0.5.12-0 python3-itoolkit 1.6.1-1

We had a requirements to use python39 in an other project, so we also installed the following python39 modules: python39 3.9.10-1
python39-ibm_db 2.0.5.12-1
python39-itoolkit 1.7.0-1

That seems to have broke the Power IBM i collection for Ansible, a simple ansible playbook to just run an CL command to execute a SNDMSG now fails.


This playbook worked perfectly before we installed the python39 modules.

TASK [run cl first command] ** fatal: [myhost.mydomain.com]: FAILED! => {"changed": false, "module_stderr": "Shared connection to myhost.mydomain.com closed.\r\n", "module_stdout": "\r\n{\"cmd\": \"SNDMSG MSG('Testing sending messages from Ansible') TOUSR(MYUSER)\", \"joblog\": false, \"rc\": 0, \"stdout\": \"{'success': \\"+++ success SNDMSG MSG('Testing sending messages from Ansible') TOUSR(MYUSER)\\"}\", \"stderr\": \"\", \"job_log\": [], \"start\": \"2022-03-08 12:23:43.685618\", \"end\": \"2022-03-08 12:23:43.853320\", \"delta\": \"0:00:00.167702\", \"job_name\": \"Job name not available. \", \"invocation\": {\"module_args\": {\"cmd\": \"SNDMSG MSG('Testing sending messages from Ansible') TOUSR(MYUSER)\", \"asp_group\": \"*SYSBAS\", \"joblog\": false, \"become_user\": null, \"become_user_password\": null}}}\r\nException ignored in: <function IBMiModule.del at 0x70000000075eaf0>\r\nTraceback (most recent call last):\r\n File \"/tmp/ansible_ibmi_cl_command_payload_q2nmgqhz/ansible_ibmi_cl_command_payload.zip/ansible_collections/ibm/power_ibmi/plugins/module_utils/ibmi/ibmi_module.py\", line 199, in del\r\n File \"/tmp/ansible_ibmi_cl_command_payload_q2nmgqhz/ansible_ibmi_cl_command_payload.zip/ansible_collections/ibm/power_ibmi/plugins/module_utils/ibmi/ibmi_module.py\", line 227, in itoolkit_close_connection\r\n File \"/tmp/ansible_ibmi_cl_command_payload_q2nmgqhz/ansible_ibmi_cl_command_payload.zip/ansible_collections/ibm/power_ibmi/plugins/module_utils/ibmi/ibmi_module.py\", line 223, in close_db_connection\r\nException: Failed to close connect from database: {inst}\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 0}

PLAY RECAP *** myhost.mydomain.com : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

The thing is that the command actually are working and the message are sent, but the playbook indicates it has failed.

Python3 and Python39 should be able to co-exist on the same IBM i without breaking anything.

pengzengyufish commented 2 years ago

@krka01 Hi, Have you set the ansible_python_interpreter in ansible server's ansible/hosts? Like ansible_python_interpreter=/QOpenSys/pkgs/bin/python3? You can set the ansible_python_interpreter to your IBM i python3, but not Python39. And try again. Thank you.

krka01 commented 2 years ago

Yes, I have set the ansible_python_interpreter in the hosts_ibmi file on the server:

[all:vars] ansible_python_interpreter="/QOpensys/pkgs/bin/python3" ansible_ssh_common_args='-o StrictHostKeyChecking=no'

We have tried to install the python39 modules on another IBM i host now and as soon as the python39 modules are installed it starts to fail.

SGI495 commented 2 years ago

Hi, I'm getting the same error in the ibm.power_ibmi.ibmi_object_save module after upgrading to python 3.9. It looks like there's some issue in either the python39-ibm_db or the python39-itoolkit package...

@krka01 It does work for me when I explicitly set the ansible_python_interpreter to /QOpenSys/pkgs/bin/python3.6 so try that as a workaround unless you uninstalled the 3.6 packages. They wouldn't have been removed by just installing the 3.9 packages.

You can do "update-alternatives --display python3" do show what versions are installed and which one is linked to /QOpenSys/pkgs/bin/python3.

krka01 commented 2 years ago

Thanks @SGI495

Indeed, you are absolutely correct, python3 have now been linked to version 3.9 on our systems:

python --version
Python 3.9.10
$
python3 --version
Python 3.9.10
$
python3.6 --version Python 3.6.15
$
python3.9 --version Python 3.9.10

Setting the ansible_python_interpreter to /QOpenSys/pkgs/bin/python3.6 seems to solve the issue.

Why didn't I think about this, when the recommendation is to use the fully versioned command: https://ibmi-oss-docs.readthedocs.io/en/latest/python/README.html#which-python-command-to-use-outside-of-a-virtual-environment

Anyway, thanks again @SGI495

Maybe the instructions should be updated to "hardcode" the ansible_python_interpreter to version 3.6

changlexc commented 2 years ago

This is due a behavior change of itoolkit for python39. We will give a fix in next release. For now, you can add the below code to the place where import DatabaseTransport to fix the issue. change from itoolkit.transport import DatabaseTransport to

from itoolkit.transport import DatabaseTransport as BaseDatabaseTransport

class DatabaseTransport(BaseDatabaseTransport):
    def _close(self):
        """Don't close connection, we'll manage it ourselves"""
        pass

More detail about itoolkit behavior changes and how to resolve the issue, refer to https://github.com/IBM/python-itoolkit/issues/72

robgjertsen1 commented 6 months ago

I believe this was fixed. I did not see this with 2.0.0 when testing an IBM i as control node.

krka01 commented 6 months ago

Yes, you are right, this issue was fixed a long time ago