sap-linuxlab / community.sap_libs

Automation for SAP - Collection of Ansible Modules for SAP for low-level activities which are highly reusable
Apache License 2.0
16 stars 7 forks source link

select statement against hana runs into python error #48

Open woreis opened 1 week ago

woreis commented 1 week ago

Summary

Hi, I just wanted to test sap_hdbsql.py and immediately run into an issue.

When I run this, I get the error shown below. But of course the struct.py file can be found on the target system.

Any idea, what could cause this problem ? Help would be appreciated, Thanks, Wolfgang

Issue Type

Bug Report

Component Name

sap_libs, module sap_hdbsql.py

Ansible Version

ansible [core 2.16.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/bechtle/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /etc/ansible/{{ ANSIBLE_HOME ~ "/collections:/usr/share/ansible/collections:/etc/ansible/collections" }}
  executable location = /usr/bin/ansible
  python version = 3.12.1 (main, Feb 21 2024, 10:25:11) [GCC 8.5.0 20210514 (Red Hat 8.5.0-21)] (/usr/bin/python3.12)
  jinja version = 3.1.2
  libyaml = True

community.sap_libs Version

[root@vcomprdsat001 community]# ansible-galaxy collection list

# /usr/share/ansible/collections/ansible_collections
Collection                  Version
--------------------------- -------
ansible.posix               1.5.4
community.general           8.6.0
community.sap_install       1.4.0
community.sap_libs          1.4.2
redhat.rhel_system_roles    1.23.0
redhat.satellite            4.0.0
redhat.satellite_operations 2.1.0

Configuration

$ ansible-config dump --only-changed

OS / Environment

RHEL 9

Steps to Reproduce

---

- hosts: '{{ ho | default([]) }}'

  tasks:
  - name: Simple select query
    become: true
    become_user: idhadm
    become_flags: '-i'
    community.sap_libs.sap_hdbsql:
      sid: "IDH"
      database: "SYSTEMDB"
      instance: "00"
      userstore: true
      user: "USER"
      host: "some.host:port"
      query: select user_name from users

Expected Results

I expected the List of users to be shown.

Actual Results

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named '_struct'
fatal: [vintdevhdb001.fdz.internal]: FAILED! => 
{
    "changed": false,
    "module_stderr": "Shared connection to som.host closed.\r\n",
    "module_stdout": "
        Traceback (most recent call last):\r\n File "/var/tmp/ansible-tmp-1725457957.175195-2959474-12846379217444/AnsiballZ_sap_hdbsql.py",
        line 107,in \r\n _ansiballz_main()\r\n File "/var/tmp/ansible-tmp-1725457957.175195-2959474-12846379217444/AnsiballZ_sap_hdbsql.py",
        line 24,in _ansiballz_main\r\n import base64\r\n File "/usr/sap/IDH/HDB00/exe/Python3/lib/python3.8/base64.py",
        line 10,in \r\n import struct\r\n File "/usr/sap/IDH/HDB00/exe/Python3/lib/python3.8/struct.py",
        line 13,in \r\n from _struct import *\r\nModuleNotFoundError: No module named '_struct'
        \r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

But the file exists on the target:

[root@some.host] ~]# ls -l /usr/sap/IDH/HDB00/exe/Python3/lib/python3.8/struct.py
-r--r--r--. 1 idhadm sapsys 257 Jul 11 22:49 /usr/sap/IDH/HDB00/exe/Python3/lib/python3.8/struct.py

Code of Conduct

woreis commented 1 week ago

It works, when the become_user attribute is omitted and I pass password instead of hdbuserstore.

sean-freeman commented 1 week ago

@woreis Please first check the System Python versus the user Python. The Ansible Module sap_hdbsql does not import struct, it is imported at a much lower level and without reading your updated comment - I would have said become_user is problematic.

[root@sandbox ~]# $(which python) -c "help('modules')" | grep struct
[root@sandbox ~]# su - sbxadm
[sbxadm@sandbox ~]# $(which python) -c "help('modules')" | grep struct
woreis commented 1 week ago

Hi Sean, I found out when I omit "become_flags: '-i'" the above playbook works. But nevertheless the output of the above commands is:

[root@some.host ~]# $(which python) -c "help('modules')" | grep struct _imp datetime numbers struct _struct getpass pycparser urllib3 [root@some.host ~]# su - idhadm idhadm@vintdevhdb001.fdz:/usr/sap/IDH/HDB00> $(which python) -c "help('modules')" | grep struct _struct libhdbconssrv libhdbpreprocessorclient pipes distutils libhdbexprutils libhdbsqlscriptcodegen struct