+
Skip to content

Failed to import the required Python library (netaddr) #352

@TEDSv

Description

@TEDSv
SUMMARY

I have spent 2 days already and I cant fix that error. And I dont know what to do, please help :)
When I run this task:

    - name: task netaddr
      debug:
        msg: "{{ '192.168.1.1' | ansible.utils.ipaddr('address') }}"

I get the error: Failed to import the required Python library (netaddr). I tried install also python3-netaddr, with become and with extra_args: "--user", but still same error.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible.utils.ipaddr

ANSIBLE VERSION
ansible [core 2.14.5]
  config file = None
  configured module search path = ['/home/semaphore/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /home/semaphore/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.8 (main, Feb 19 2024, 22:58:08) [GCC 12.2.1 20220924] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
ansible.netcommon             4.1.0
ansible.posix                 1.5.2
ansible.utils                 2.9.0
CONFIGURATION
~ $ ansible-config dump --only-changed
CONFIG_FILE() = None
HOST_KEY_CHECKING(env: ANSIBLE_HOST_KEY_CHECKING) = False
OS / ENVIRONMENT

target os - ubuntu 22.04, clean fresh virtual machine

STEPS TO REPRODUCE
- name: Playbook netaddr
  hosts: all
  vars:
    ansible_python_interpreter: /usr/bin/python3

  tasks:

    - name: Install packages
      apt:
        name:
          - python3
          - python3-pip
        state: present
      become: yes

    - name: install netaddr with pip3
      pip:
        name: netaddr
        state: present
        executable: pip3
        extra_args: "--user"
      vars:
        ansible_python_interpreter: /usr/bin/python3

    - name: check netaddr
      command: python3 -c "import netaddr; print(netaddr.__version__)"
      register: netaddr_version

    - name: show version netaddr
      debug:
        msg: "Netaddr version: {{ netaddr_version.stdout }}"

    - name: check python
      command: which python3
      register: python_path

    - name: show python
      debug:
        msg: "Python: {{ python_path.stdout }}"

    - name: Ensure modules are installed
      pip:
        name:         [ "netaddr"]
        extra_args:   "--user"
      vars:
        ansible_python_interpreter: "/usr/bin/python3"

    - name: task netaddr
      debug:
        msg: "{{ '192.168.1.1' | ansible.utils.ipaddr('address') }}"
EXPECTED RESULTS
ACTUAL RESULTS

"msg": "Failed to import the required Python library (netaddr) on e9498466e11b'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"
image

"msg": "Netaddr version: 1.2.1"
"msg": "Python: /usr/bin/python3"

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs_infoThis issue requires further information. Please answer any outstanding questions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载