Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oci python sdk required for this module - random encounter #255

Open
khain0 opened this issue Nov 8, 2023 · 8 comments
Open

oci python sdk required for this module - random encounter #255

khain0 opened this issue Nov 8, 2023 · 8 comments

Comments

@khain0
Copy link

khain0 commented Nov 8, 2023

Issue Report

Error "oci python sdk required for this module" appears randomly when oci python sdk is used via OCI collection inside Execution Environment in Ansible Automation Platform. I built an image with ansible-builder and imported it as Execution Environment. Templates are run every day which executes starts and stops of instances (Virtual Machines) inside OCI. The code is executed inside EE in purpose (using local_actions in ansible module) to be able to start OCI instance which is currently not running.
The thing is a template works normally with the EE in sense python sdk is available. On average once every several dozen of launching the template the issue occurs: OCI python sdk is missing. I would like to point out that NO changes are made to EE nor template nor playbook. Red Hat Support Team pointed out that this issue be inside the code of oci_version_utils.py

A clear and concise description of what the issue is.

When template is started inside Execution Environment sometimes it reports that OCI python sdk is missing.

A clear and concise description of what you expected to happen.

When template is started inside Execution Environment it always finds OCi python SDK

  • OS version: Red Hat Enterprise Linux 8.8

  • Ansible version:

    ansible [core 2.15.4]

  • OCI Python SDK version:

    python3.9 -c "import oci;print(oci.version)"
    2.114.0

  • OCI Ansible Modules version:

ansible-galaxy collection list

/home/runner/.ansible/collections/ansible_collections

Collection Version


oracle.oci 4.33.0

Ansible playbook to reproduce the issue


  • name: Including environemnt specific variables
    include_vars: "{{ oci_env }}.yml"
    tags: always

  • name: Get all instances in compartment
    local_action:
    module: oci_compute_instance_facts
    compartment_id: "{{ compartment_id }}"
    register: instances_list
    tags: always

@dineshsuthar786
Copy link
Member

@khain0 Can you follow the steps from this troubleshooting guide to resolve the issue. If you still face the issue, please enable the debug mode using logging guide and share debug logs with us to help us identify the issue.

@khain0
Copy link
Author

khain0 commented Nov 13, 2023

OCI python SDK is installed in the image and Execution Environment works as intended most of the time (it starts OCI instances), but sometimes randomly it throws an error "oci python sdk required for this module." job_39509 run on 06.11.2023 with this error (job file attached), but since that time I had almost 100 job with success execution. The error occurs exactly like this since may 2023 - once every few dozen template runs it fails. It does not matter which version of oci python sdk I use.
job_39509.txt

@khain0
Copy link
Author

khain0 commented Nov 20, 2023

Do you have any conclusions regarding this issue?

@dineshsuthar786
Copy link
Member

@khain0 By default, Ansible gathers facts and executes all tasks on the machines that match the hosts line of your playbook. You can delegate tasks to a different machine or group using delegate_to or local_action.

As I can see in your playbook that you are using local_action, So this random occurrence of oci python sdk required for this module error might be due to that. When this error occurs, either target host (where ansible task is actually targeted to execute) does not have oci python sdk installed or it might be installed on different execution environment than oci-ansible-collection is installed. if it's already installed, you can set the python interpreter path. you can find details about setting python interpreter path in our troubleshooting guide

Attached log job_39509.txt also confirms that Get all instances in compartment task is executed in a different host than other ansible tasks. So, make sure all the targeted hosts has oci python sdk installed and correct python interpreter path is set in case of already installed.

@khain0
Copy link
Author

khain0 commented Nov 28, 2023

oci-ee_v3.yml.txt
All tasks are executed on the same Execution Environment it is on purpose due to using local_action in tasks inside playbook, but error occurrence is random. Most of the time oci python sdk is available and the playbook is finished successfully, but once in about 100 starts the playbook cannot find oci python sdk in EE.
I don't know how you figured that out that task "Get all instances in compartment" is run on different EE, but it is not possible - on Ansible Automation Platform a playbook can be run only on one EE. Also all tasks uses local_action - "Get all instances in compartment" is no exception here. Python interpreter is set manually to version 3.9 (one and only installed inside Execution Environment), so there is no possibility that playbook uses other version of python. I also use alternatives when building EE to make sure that always correct python is reached.
I am struggling with this error since May 2023. Red Hat Support gave me instruction how to try to get rid of random occurrence of the issue - they got one clue that piece of code in python sdk works incorrectly that's why sdk is not found from time to time. Oracle Support pointed out that sdk is a community module, so they are unable to provide any changes in the code.

I came with this error here to indicate that there is a bug in your code and I would like you to start to try to find the error. Giving advice which are inconsistent with reality does not help at all.

Attachemnts: yaml file used to build EE with command: ansible-builder build -v 3 --no-cache -f oci-ee_v3.yml -t localhost/oci:3.02

@khain0
Copy link
Author

khain0 commented Dec 4, 2023

Do you have any clue what could be wrong?

@tuxonfire
Copy link

tuxonfire commented Dec 19, 2023

@dineshsuthar786 In regards this issue, the python interpreter is being forced to be used, and there is only one python installed even with forcing the interpreter, the error of the collection not recognizing the interpreter is showed.
We have investigated the code that performs the validation in question and the error comes from the oci_version_utils.py code in which these versions are tested:
From the playbook log:

        "2023-11-06,02:00:14 DEBUG oci_version_utils.py:55 Ansible Version: 2.15.4",
        "2023-11-06,02:00:14 DEBUG oci_version_utils.py:100 OCI-Python-Sdk path: Not installed",

The import from oci succeeds inside the container image (execution environment), this suggests a problem with the collection code where they test the imports available, as follows is the python installed in the container image that is randomly failing:

bash-4.4$ python -c "import oci;print(oci.__version__)"
2.114.0
bash-4.4$ python3 -c "import oci;print(oci.__version__)"
2.114.0
bash-4.4$ python3.9 -c "import oci;print(oci.__version__)"
2.114.0

There could be issues with how the code handles its python imports.
Thanks.

@khain0
Copy link
Author

khain0 commented Jan 8, 2024

Gentle reminder, last comment was done over a month ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants