# Facing issues when using ansible 2.16 with python 3.11

**URL:** <https://forum.ansible.com/t/facing-issues-when-using-ansible-2-16-with-python-3-11/45328>\
**Category:** Get Help\
**Tags:** rhel9, ansible-core\
**Created:** [February 13, 2026, 4:06am UTC](https://forum.ansible.com/t/facing-issues-when-using-ansible-2-16-with-python-3-11/45328 "2026-02-13T04:06:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harshit\_Gupta](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harshit_gupta/32/8010_2.png) [@Harshit\_Gupta](https://forum.ansible.com/u/Harshit_Gupta)\
**Post date:** [February 13, 2026, 4:06am UTC](https://forum.ansible.com/t/facing-issues-when-using-ansible-2-16-with-python-3-11/45328/1 "2026-02-13T04:06:11Z")

</div>

I am facing below issue when gathering facts with ansible 2.16. As we are upgrading our environment from ansible 2.14 to ansible 2.16.

````auto
TASK [Gathering Facts] *************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => changed=false
  ansible_facts: {}
  failed_modules:
    ansible.legacy.setup:
      exception: |-
        Traceback (most recent call last):
          File "/root/.ansible/tmp/ansible-tmp-1770954071.9596925-56009-84847984617131/AnsiballZ_setup.py", line 107, in <module>
            _ansiballz_main()
          File "/root/.ansible/tmp/ansible-tmp-1770954071.9596925-56009-84847984617131/AnsiballZ_setup.py", line 99, in _ansiballz_main
            invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
          File "/root/.ansible/tmp/ansible-tmp-1770954071.9596925-56009-84847984617131/AnsiballZ_setup.py", line 47, in invoke_module
            runpy.run_module(mod_name='ansible.modules.ansible.legacy.setup', init_globals=dict(_module_fqn='ansible.modules.ansible.legacy.setup', _modlib_path=modlib_path),
          File "<frozen runpy>", line 226, in run_module
          File "<frozen runpy>", line 98, in _run_module_code
          File "<frozen runpy>", line 88, in _run_code
          File "/tmp/ansible_ansible.legacy.setup_payload_xfjj0shm/ansible_ansible.legacy.setup_payload.zip/ansible/modules/ansible/legacy/setup.py", line 175, in <module>
        ModuleNotFoundError: No module named 'ansible.modules.ansible.module_utils'
      failed: true
      module_stderr: |-
        Traceback (most recent call last):
          File "/root/.ansible/tmp/ansible-tmp-1770954071.9596925-56009-84847984617131/AnsiballZ_setup.py", line 107, in <module>
            _ansiballz_main()
          File "/root/.ansible/tmp/ansible-tmp-1770954071.9596925-56009-84847984617131/AnsiballZ_setup.py", line 99, in _ansiballz_main
            invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
          File "/root/.ansible/tmp/ansible-tmp-1770954071.9596925-56009-84847984617131/AnsiballZ_setup.py", line 47, in invoke_module
            runpy.run_module(mod_name='ansible.modules.ansible.legacy.setup', init_globals=dict(_module_fqn='ansible.modules.ansible.legacy.setup', _modlib_path=modlib_path),
          File "<frozen runpy>", line 226, in run_module
          File "<frozen runpy>", line 98, in _run_module_code
          File "<frozen runpy>", line 88, in _run_code
          File "/tmp/ansible_ansible.legacy.setup_payload_xfjj0shm/ansible_ansible.legacy.setup_payload.zip/ansible/modules/ansible/legacy/setup.py", line 175, in <module>
        ModuleNotFoundError: No module named 'ansible.modules.ansible.module_utils'
      module_stdout: ''
      msg: |-
        MODULE FAILURE
        See stdout/stderr for the exact error
      rc: 1
  msg: |-
    The following modules failed to execute: ansible.legacy.setup```

I am using virtual env. Let me know incase you need more information
````

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [February 13, 2026, 7:59pm UTC](https://forum.ansible.com/t/facing-issues-when-using-ansible-2-16-with-python-3-11/45328/2 "2026-02-13T19:59:14Z")

</div>

Do you have a setup module in any of the [module paths](https://docs.ansible.com/projects/ansible/latest/reference_appendices/config.html#default-module-path) or in a library/ directory alongside your playbook? You can check the configured module paths with `ansible-config dump | grep DEFAULT_MODULE_PATH`. I can reproduce this by copying the [builtin setup module](https://github.com/ansible/ansible/blob/stable-2.16/lib/ansible/modules/setup.py) into my library/, but it doesn’t work on 2.14 either. Changing the relative import (`from ..module_utils.basic import AnsibleModule`) to an absolute import (`from ansible.module_utils.basic import AnsibleModule`) fixes it.

---

<div class="post-metadata">

**Author:** ![Harshit\_Gupta](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harshit_gupta/32/8010_2.png) [@Harshit\_Gupta](https://forum.ansible.com/u/Harshit_Gupta)\
**Post date:** [February 18, 2026, 8:34am UTC](https://forum.ansible.com/t/facing-issues-when-using-ansible-2-16-with-python-3-11/45328/3 "2026-02-18T08:34:36Z")

</div>

> [@shertel](#):
>
> ansible-config dump | grep DEFAULT\_MODULE\_PATH

We are using pyenv for ansible 2.16 and here is the cfg file:

```auto
(pyenv-ansible-2.16) [dev] root@foreman:pyenv-ansible-2.16# cat ../ansible-2.16-base.cfg
[defaults]
stdout_callback = yaml
library = pyenv-ansible-2.16/lib/python3.11/site-packages/ansible/modules:ansible-module-foreman:./extra/ceph-ansible/library
action_plugins = plugins/actions:./extra/ceph-ansible/plugins/actions
callback_plugins = plugins/callback
filter_plugins = plugins/filter:./filter_plugins
lookup_plugins = lookup_plugins
roles_path = ./extra/kubespray/roles/:./roles:./extra/ceph-ansible/roles

```

If I remove this path `pyenv-ansible-2.16/lib/python3.11/site-packages/ansible/modules` then I didn’t see this issue. Also this folder contain below files:

```auto
(pyenv-ansible-2.16) [dev] root@foreman:modules# ls | xargs
add_host.py apt_key.py apt.py apt_repository.py assemble.py assert.py async_status.py async_wrapper.py blockinfile.py command.py copy.py cron.py deb822_repository.py debconf.py debug.py dnf5.py dnf.py dpkg_selections.py expect.py fail.py fetch.py file.py find.py gather_facts.py getent.py get_url.py git.py group_by.py group.py hashivault hostname.py import_playbook.py import_role.py import_tasks.py include_role.py include_tasks.py include_vars.py __init__.py iptables.py known_hosts.py lineinfile.py meta.py package_facts.py package.py pause.py ping.py pip.py __pycache__ raw.py reboot.py replace.py rpm_key.py script.py service_facts.py service.py set_fact.py set_stats.py setup.py shell.py slurp.py stat.py subversion.py systemd.py systemd_service.py sysvinit.py tempfile.py template.py unarchive.py uri.py user.py validate_argument_spec.py wait_for_connection.py wait_for.py yum.py yum_repository.py

```

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [February 18, 2026, 9:01pm UTC](https://forum.ansible.com/t/facing-issues-when-using-ansible-2-16-with-python-3-11/45328/4 "2026-02-18T21:01:33Z")

</div>

The ansible.builtin paths don’t need to be configured, so removing it makes sense. At best it does nothing.

The error occurs if the setup.py in your library is not the same as the `ansible.builtin.setup` module (and is executed as `ansible.legacy.setup`, like `gather_facts` does by default). The relative import works for the package `ansible.modules.setup`, but you can see in your traceback that the package is `ansible.modules.ansible.legacy.setup` (which would require a relative import like `from ....module_utils.basic import AnsibleModule` or absolute import instead).
