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

ERROR: "msg": "Failed to import the required Python library (pyrfc) on HOST #24

Closed picoroma closed 1 year ago

picoroma commented 1 year ago

Summary

I have a Ansible CONTROL Node with: python version: Python 3.8.10 pyrfc version: 2.7.0

And a ansible "SAP NW" Node with: OS: SLES 15 SP2 Python 3.6.15 pyrfc: missing

When try to use the module "community.sap_libs.sap_user" to create a new USER I have the error:

"msg": "Failed to import the required Python library (pyrfc) on myhostname's Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"

Question1: Do I need to install the pyrfc even on SAP NW host ? (because this is not possible now) QUestion2: How to correct the error ? THX

Issue Type

Bug Report

Component Name

sap_user

Ansible Version

$ ansible --version
ansible [core 2.13.1]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ubuntu/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ubuntu/.local/bin/ansible
  python version = 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True

community.sap_libs Version

$ ansible-galaxy collection list community.sap_libs
Collection         Version
------------------ -------
community.sap_libs 1.1.0

# /home/ubuntu/.ansible/collections/ansible_collections
Collection         Version
------------------ -------
community.sap_libs 1.4.0

Configuration

$ ansible-config dump --only-changed
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/etc/ansible/hosts']
INTERPRETER_PYTHON(/etc/ansible/ansible.cfg) = auto

OS / Environment

Source OS (Ansible Control Node): Ubuntu 20.04.5 LTS Target OS (SAP NW): SLES 15 SP2

Steps to Reproduce

---
  - name: SAP_USER
    hosts: SAP_S4HANA
    tasks:
        - name: Create SAP User
          community.sap_libs.sap_user:
            conn_username: 'ADMIN'
            conn_password: 'MyAdminPSWD'
            host: myhostname
            sysnr: '00'
            client: '200'
            state: present
            username: ANSIBLE
            firstname: first_admin
            lastname: last_admin
            email: admin@test.de
            password: Test123456
            useralias: ANSIBLE-ADMIN
            company: DEFAULT_COMPANY
            roles:
              - "SAP_ALL"

Expected Results

Error NA

Actual Results


NA

Code of Conduct

rainerleber commented 1 year ago

Hi @picoroma, thank you for open this Issue. It is not necessary to install pyrfc on the nw host because we always do rfc calls.

Ansible always execute modules on the host defined on top of the playbook.

Therefore you have two possible solution and depends on the tasks which should be executed:

  1. Execute your playbook on localhost like: (Only a good approach if you execute tasks which must not executed on the NW host for example)

     - name: SAP_USER
       hosts: localhost
       tasks:
         - 
  2. use delegation:

        - name: Create SAP User
          community.sap_libs.sap_user:
            conn_username: 'ADMIN'
            conn_password: 'MyAdminPSWD'
            host: myhostname
            sysnr: '00'
            client: '200'
            state: present
            username: ANSIBLE
            firstname: first_admin
            lastname: last_admin
            email: admin@test.de
            password: Test123456
            useralias: ANSIBLE-ADMIN
            company: DEFAULT_COMPANY
            roles:
              - "SAP_ALL"
         delegate_to: localhost

The delegation could also a other foreign host. Both approaches needs the installation of pyrfc and sdk on the control node or delegate host.

If you want to use AAP or AWX you have to build a custom ee which contains pyrfc.

Please let me know if this will solve your problem.

If you have any question feel free to reach out to me.

picoroma commented 1 year ago

Hi @rainerleber ! THX to you for answer me!. I'm quite new to ANSIBLE and i have a lot of GAP on this. Anyway I have tested successfully both method you give me. One question - regarding for example "community.sap_libs.sap_user" How can I use the ANSIBLE methot to create user MASSIVELY ? Assigning each one for example different SAP Profile ? THX

rainerleber commented 1 year ago

It depends on what you want to achieve exactly a possible solution:

defining a var like:

user_groups: ''
  - { firstname: "admin_user", username: "test_admin", role: "SAP_ALL" }
  - { firstname: "monitoring_user", username: "test_mon", role: "SAP_ADMIN" }

and the task like:

    - name: Create SAP User
      community.sap_libs.sap_user:
        conn_username: 'ADMIN'
        conn_password: 'MyAdminPSWD'
        host: myhostname
        sysnr: '00'
        client: '200'
        state: present
        username: "{{ item.username }}"
        firstname: "{{ item.firstname }}"
        lastname: last_admin
        email: admin@test.de
        password: Test123456
        useralias: ANSIBLE-ADMIN
        company: DEFAULT_COMPANY
        roles:
          - "{{ item.role}}"
    loop:
      - user_groups 

You can also develop a solution reading AD user write them to a set_fact var and iterate over it for example.

picoroma commented 1 year ago

OK. I will try! THX PLEASE correct (even into the Example Documentation of the module) ... roles:

profiles:

because "SAP_ALL" is a SAP profile and NOT a SAP role!

rainerleber commented 1 year ago

Thank for the hint i will correct it :-)

rainerleber commented 1 year ago

Solved