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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Install dependencies required by the collection (adjust path to collection if ne
pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements.txt
```

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.

```

To upgrade to the latest version of Azure collection:

```bash
Expand Down