F5Networks / f5-ansible

Imperative Ansible modules for F5 BIG-IP products
GNU General Public License v3.0
376 stars 231 forks source link

Code fails to execute in version 1.22 on multiple modules "No module named 'packaging'" works fine in 1.21 or lower #2292

Open VDI-Tech-Guy opened 1 year ago

VDI-Tech-Guy commented 1 year ago
COMPONENT NAME

Seen issue in different modules (confirmed that was in these two at minimum) f5networks.f5_modules.bigip_device_info: f5networks.f5_modules.bigip_virtual_server

Environment

ANSIBLE VERSION
Using Exectuion environment with Ansible 

[rhel-user@ede7a345-c0f1-47f9-a73b-74fded8ec113 1.5-add-virtual-server]$ podman run --rm -it 7fb5f9edf3d0 /bin/bash
bash-4.4# ansible --version
ansible [core 2.12.5.post0]
  config file = None
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.13 (default, Jun 24 2022, 15:27:57) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
  jinja version = 2.11.3
  libyaml = True
BIGIP VERSION
Not BIG-IP Issue tested with Version 16.1.2.1 on every build
CONFIGURATION

Using Ansible-Builder to create Execution environment with Ansible Navigator but again doesnt matter here allows me to execute environments with repeatable executions

I can provide information how to create EE if needed and how to use Ansible-Navigator to test if you need.

OS / ENVIRONMENT

Primary OS is RHEL 8.6, using podman for Execution environment

SUMMARY

When Executing code get failure saying that "No module named 'packaging'" even though the package is installed. (No Problem in 1.21.0 or lower) only shows up in version 1.22.0

STEPS TO REPRODUCE

Using Ansible Navigator with Execution Environment with same requirements file (builds all core image the same, same verision of ansible, only thing changed in requirements file is the version of f5networks.f5_modules to test different builds.) using the execution environment to test my known working code for simple task to get info from bigip fails.

You can use the existing Latest Execution environment located at https://quay.io/repository/acme_corp/f5_ee

to do this with ansible-navigator you can create a .ansible-navigator.yml in your root directory of user executing Here is an example of mine, i compiled every version manually to test which versions worked and confirmed 1.21 worked fine and 1.22 failed.

[rhel-user@ede7a345-c0f1-47f9-a73b-74fded8ec113 1.1-get-facts]$ cat ~/.ansible-navigator.yml 
---
ansible-navigator:
  ansible:
    inventory:
      entries:
      - /home/rhel-user/lab_inventory/hosts
  execution-environment:
    container-engine: podman
    enabled: true
    #image: quay.io/acme_corp/f5_ee:1d726d9ab810d5bfc37de3e2d8d6427cc89a9bf9  # uses 1.19
    #image: quay.io/acme_corp/f5_ee:92368219aea27d5ca5fd254d9085b9f47b949315  # Uses 1.22
    image: quay.io/acme_corp/f5_ee:latest # Uses 1.22
    pull:
      policy: missing
    volume-mounts:
    - dest: /etc/ansible/
      src: /etc/ansible/
    - dest: /tmp/f5/
      src: /tmp/f5/
    - dest: /usr/share/nginx/html/asm-profiles
      src: /usr/share/nginx/html/asm-profiles
 name: GRAB F5 FACTS
  hosts: f5
  connection: local
  gather_facts: false

  tasks:
    - name: COLLECT BIG-IP FACTS
      f5networks.f5_modules.bigip_device_info:
        gather_subset:
          - system-info
        provider:
          server: "{{ ansible_host }}"
          user: "{{ ansible_user }}"
          password: "{{ ansible_password }}"
          server_port: "{{ server_port }}"
          validate_certs: false
      register: device_facts

    - name: DISPLAY COMPLETE BIG-IP SYSTEM INFORMATION
      debug:
        var: device_facts

    - name: DISPLAY ONLY THE MAC ADDRESS
      debug:
        var: device_facts['system_info']['base_mac_address']

    - name: DISPLAY ONLY THE VERSION
      debug:
        var: device_facts['system_info']['product_version']
EXPECTED RESULTS

Should have executed and output info from BIG-IP

ACTUAL RESULTS

-->

[rhel-user@ede7a345-c0f1-47f9-a73b-74fded8ec113 1.1-get-facts]$ ansible-navigator run bigip-info.yml --mode stdout

PLAY [GRAB F5 FACTS] ***********************************************************

TASK [COLLECT BIG-IP FACTS] ****************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'packaging'
fatal: [f5]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "changed": false, "msg": "Failed to import the required Python library (packaging) on 795ef0126fd3's Python /usr/libexec/platform-python. 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"}

PLAY RECAP *********************************************************************
f5                         : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
larmbuster commented 1 year ago

I'm able to replicate the issue.

wojtek0806 commented 1 year ago

when you create execution env you need to create requirements.txt file and reference it like in the example below:

https://clouddocs.f5.com/products/orchestration/ansible/devel/usage/exec-env.html

that doc needs updating to add packaging to requirements.txt

As a matter of fact build the local EE as per above instructions, and run playbook with the created container.

For now this looks like an issue with your execution environment.

VDI-Tech-Guy commented 1 year ago

@wojtek0806 - built it the way you recommended however still same issue

you can see my requirements files and execution environment.yml at

https://github.com/VDI-Tech-Guy/f5-execution-engines/tree/main/f5-test-ee

Workflow creates the following execution environment - https://quay.io/repository/f5_business_development/f5-test-ee you can setup your .ansible-navigator.yml with following line to execute on it

https://quay.io/repository/f5_business_development/f5-test-ee:latest