I have a python (v3.12.x) installation of Ansible, ansible-core, ansible-galaxy, etc. and I am unable to make any calls to ‘open_url’ or ‘get_url’ either directly or indirectly through another task that may call these two utilities.
You have to show your ansible code and the errors you receive, plus results of basic troubleshooting (example - trying these commands from the command line without ansible), or else no one will be able to assist you…
OK. My error is not stemming from any thing I am coding, other than calling our a task that makes use of ‘get_url’ or ‘open_url’. This same error crops up when I can a ‘yum’ task, a ‘dnf’ task, a ‘get_url’ direct task, ANY task that reaches out to the ‘url’ Python module.
TASK [infra.prerequisites.install : Install Prerequisite Packages] ***********************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: cannot import name ‘open_url’ from partially initialized module ‘ansible.module_utils.urls’ (most likely due to a circular import) (/tmp/ansible_ansible.legacy.dnf_payload_ak5cc1qa/ansible_ansible.legacy.dnf_payload.zip/ansible/module_utils/urls.py)
fatal: [x.x.x.x]: FAILED! => {“changed”: false, “module_stderr”: “Shared connection to [x.x.x.x] closed.\r\n”, “module_stdout”: “Traceback (most recent call last):\r\n File "/var/home/ec2-user/.ansible/tmp/ansible-tmp-1731341024.3789487-31629-124459087336013/AnsiballZ_dnf.py", line 107, in \r\n _ansiballz_main()\r\n File "/var/home/ec2-user/.ansible/tmp/ansible-tmp-1731341024.3789487-31629-124459087336013/AnsiballZ_dnf.py", line 99, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File "/var/home/ec2-user/.ansible/tmp/ansible-tmp-1731341024.3789487-31629-124459087336013/AnsiballZ_dnf.py", line 47, in invoke_module\r\n runpy.run_module(mod_name=‘ansible.modules.dnf’, init_globals=dict(_module_fqn=‘ansible.modules.dnf’, _modlib_path=modlib_path),\r\n File "", line 226, in run_module\r\n File "", line 98, in _run_module_code\r\n File "", line 88, in _run_code\r\n File "/tmp/ansible_ansible.legacy.dnf_payload_ak5cc1qa/ansible_ansible.legacy.dnf_payload.zip/ansible/modules/dnf.py", line 404, in \r\n File "/tmp/ansible_ansible.legacy.dnf_payload_ak5cc1qa/ansible_ansible.legacy.dnf_payload.zip/ansible/module_utils/urls.py", line 18, in \r\nImportError: cannot import name ‘open_url’ from partially initialized module ‘ansible.module_utils.urls’ (most likely due to a circular import) (/tmp/ansible_ansible.legacy.dnf_payload_ak5cc1qa/ansible_ansible.legacy.dnf_payload.zip/ansible/module_utils/urls.py)\r\n”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}
Anyone have any clues on this? I am using Ubuntu 24.04 with Python3.12 installed Ansible.
One thing that I have seen to fix this issue is to apt-get install ansible INSTEAD of python install ansible. For some reason, the python-installed Ansible is hitting this error.
By “Python installed Ansible” do you mean Ansible was installed using pip3 or pipx or something else?
If you have Ansible installed in your users $HOME directory how are you running it to ensure that this version is used rather a system packaged version of Ansible, eg is it in ~/.local/bin and does that directory come before others in your $PATH?
That all looks fine, perhaps uninstall the system Ansible to be sure that the issue isn’t caused by different versions conflicting? However this isn’t an issue I’ve had — all the Ansible controllers I use have a Debian Ansible and a pipx installed Ansible in my $HOME… (I use the Debian Ansible to install the latest Ansible using pipx).
It turns out this Ubuntu image doesn’t have system ansible installed. I think reverting back to RPM-based Ansible installations is what fixes this issue, if I can remember correctly.
I prefer the pip3 installation of Ansible over the system installed Ansible, but I can’t seem to get around using tasks that ultimately hit the get_url or open_url.
Very frustrating. And apparently no one else on the Internets has seen this issue before.
So I bit the bullet and apt installed Ansible-core and Ansible, to go along with my pip3 installed Ansible and ran my playbook and got the same “cannot import name ‘open_url’ from partially initialized modules 'ansible.module_utils.urls”
I am starting to believe this is just a pathing issue of some sort. The module is there since ansible-core brings along all of the ansible.builtin.* tasks, but which pathing is limiting this from being found?
I’m sitting in $HOME/.ansible and can find the urls.py module at ./plugins/module_utils/urls.py. What do I need to set/change to tell Ansible to look here too?