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

Add pipx alternative for deps installation #1797

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

dxmann73
Copy link

@dxmann73 dxmann73 commented Jan 5, 2025

SUMMARY

After many struggles to get the azure collection installed on Ubuntu, I have finally figured out how to use pipx. It has helped me a lot and I'd llike to add it to the docs.

ISSUE TYPE
  • Docs Pull Request

Or, if you can't use pip, e.g. when you are on Ubuntu/Debian:

```bash
pipx runpip ansible install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements.txt
Copy link
Collaborator

@Fred-sun Fred-sun Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dxmann73 This only installs these dependencies in the isolated virtual environment ansible, but how do we call these dependencies when we run the script? Can you describe it here? Thank you!

Copy link
Author

@dxmann73 dxmann73 Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this actually to work around an issue I had working with the Azure collection on my machine (Ubuntu)

First, following https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-and-upgrading-ansible-with-pipx

sudo apt install pipx
pipx ensurepath
source ~/.bashrc
pipx install --include-deps ansible

With ansible --version showing it was correctly installed, following https://galaxy.ansible.com/ui/repo/published/azure/azcollection/docs/ I did

ansible-galaxy collection list | grep azure

and saw it was showing up 2x times. If it hadn't been there I would have done (and tried)

ansible-galaxy collection install azure.azcollection --force

But that didn't change much. Because when trying to work with the Azure collection (as user traefik-vm-adm), I got the following error

ansible localhost -m azure.azcollection.azure_rm_resourcegroup -a "name=foo location=swedencentral"

[WARNING]: No inventory was parsed, only implicit localhost is available
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'azure.mgmt'
localhost | FAILED! => {
    "changed": false,
    "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on staging-traefik-vm's Python /home/traefik-vm-adm/.local/share/pipx/venvs/ansible/bin/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"
}

To resolve the error, I tried to pipx inject ansible azure which failed with a message saying the azure module is deprecated starting with version 5.0.0

So what I did was install the dependencies

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

and make sure the azure package was there with

ll ~/.local/share/pipx/venvs/ansible/lib/python3.12/site-packages | grep azure

I don't remember exactly if it worked then and there, I may have injected azure v4 as well using

pipx inject ansible azure==4.0.0

Being new to Python it took a considerable amount of time to actually figure all this out to make it work. So I figured at least the pipx runpip part should go into the docs.

Cheers
Dave

Copy link
Author

@dxmann73 dxmann73 Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: Many docs say to install stuff just using pip. Ubuntu does not have pip and when you try to install anything with it, it will complain that it will break the system if you do so, talking about managed environments or somesuch and being kinda vague about what the options are. So I feel like more docs should actually mention that.

@Fred-sun Fred-sun added question Further information is requested medium_priority Medium priority work in In trying to solve, or in working with contributors labels Jan 8, 2025
@Fred-sun Fred-sun added ready_for_review The PR has been modified and can be reviewed and merged enhancement New feature or request and removed question Further information is requested work in In trying to solve, or in working with contributors labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request medium_priority Medium priority ready_for_review The PR has been modified and can be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants