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

ModuleNotFoundError: No module named 'azure' #1415

Open
klemen-df opened this issue Jan 22, 2024 · 12 comments
Open

ModuleNotFoundError: No module named 'azure' #1415

klemen-df opened this issue Jan 22, 2024 · 12 comments
Labels
medium_priority Medium priority not a bug Not a bug question Further information is requested work in In trying to solve, or in working with contributors

Comments

@klemen-df
Copy link

SUMMARY
  • Ubuntu 22.04, latest paches installed
  • Installed ansible (ansible-core-2.15.8-1ppa~jammy) , followed the instructions here
    -- sudo apt update
    -- sudo apt install software-properties-common
    -- sudo add-apt-repository --yes --update ppa:ansible/ansible
    -- sudo apt install ansible
  • installed azure collection, followed the instructions here
    -- ansible-galaxy collection install azure.azcollection
    -- pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt

When I run the playbook I get:
fatal: [worker1 -> localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on ansiblerunner'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"}

ISSUE TYPE
  • Bug Report
COMPONENT NAME

azure.azcollection

ANSIBLE VERSION
ansible [core 2.15.8]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user1/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/user1/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True

ansible-galaxy collection list
COLLECTION VERSION
# /home/user1/.ansible/collections/ansible_collections
Collection         Version
------------------ -------
ansible.posix      1.5.4
azure.azcollection 2.1.1
community.general  8.2.0
CONFIGURATION

OS / ENVIRONMENT

Ubuntu 22.04, latest patches installed

STEPS TO REPRODUCE

Install Ubuntu22 (standard installation), update OS, install ansible by standard instructions and install collection with standard instructions

EXPECTED RESULTS

Module should be fine

ACTUAL RESULTS

Module not found.


@klemen-df
Copy link
Author

Added fact, if I install ansible with pip then it works.

But since the Ubuntu22/ansible/ansible collections are a common/standard thing I think it would be good to document this (how to make it work without pip or document you must use pip.

@Fred-sun Fred-sun added the work in In trying to solve, or in working with contributors label Jan 23, 2024
@Fred-sun
Copy link
Collaborator

@KlemenDanfoss You install all the dependent files that are required for pip installation. If your pip installation dependency fails, you will be prompted with the above error! Thanks!

pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt

@klemen-df
Copy link
Author

@Fred-sun ; I wrote in the instructions that this is a step I execute - still doesn't work.

@Fred-sun
Copy link
Collaborator

@KlemenDanfoss Build the environment according to the steps in the newly built ubuntu22.04. After the environment is completed, it can run normally. Can you check that each of your commands has been executed successfully? Could you please provide your playbook and 'pip3 list' information? Thank you very much!

@Fred-sun Fred-sun added question Further information is requested medium_priority Medium priority labels Jan 25, 2024
@Fred-sun
Copy link
Collaborator

@klemen-df However, I built a new virtual machine locally, performed the actions you installed above, and did not encounter any errors when executing the script. Thank you!

1. Install ansible:
-- sudo apt update
-- sudo apt install software-properties-common
-- sudo add-apt-repository --yes --update ppa:ansible/ansible
-- sudo apt install ansible
2. Install azure.azcollection
-- ansible-galaxy collection install azure.azcollection
3. Install pip3:
sudo apt install python3-pip
4. Install requirement-azure.txt
-- pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt

@Fred-sun Fred-sun added the not a bug Not a bug label Apr 18, 2024
@Fred-sun
Copy link
Collaborator

@klemen-df Can you provide your version of the system and follow the steps above, what is the result?

@klemen-df
Copy link
Author

klemen-df commented May 10, 2024

Hi,

it works with a plain Ubuntu image.

It doesn't work with Ubuntu image for Azure Microsoft Hosted agents - link.

But there ansible is installed with pipx.

@Fred-sun
Copy link
Collaborator

@klemen-df I'm not sure. Can you speak more clearly? Thank you!

@klemen-df
Copy link
Author

If you run a pipeline in Azure Devops and you run it on the shared, Microsoft provided runners (the description of the image is in the link above) you run with packages that are preinstalled. On the image Ansible is preinstalled with pipx.

So, if you use the preinstalled Ansible and 'just' install 'ansible-galaxy collection install azure.azcollection' it doesnt work (error above)

Also, if you remove ansible with pipx and install 'fresh' (commands above, the tutorial ones) it also doesnt work (same error).

@Fred-sun
Copy link
Collaborator

Fred-sun commented May 10, 2024

If the reinstallation didn't work, what was this mistake?

@klemen-df
Copy link
Author

When I run the playbook I get:
fatal: [worker1 -> localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on ansiblerunner'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"}

When I run the playbook I get:
fatal: [worker1 -> localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on ansiblerunner'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"}

@Fred-sun
Copy link
Collaborator

@klemen-df From the error point of view, the installed package is not found, causing such an error to be triggered. These dependencies are not installed, or under different python environments. I occasionally get this error when installing, but reinstalling is fine! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority not a bug Not a bug question Further information is requested work in In trying to solve, or in working with contributors
Projects
None yet
Development

No branches or pull requests

2 participants