ansible-collections / ansible-consul

:satellite: Ansible role for Hashicorp Consul clusters
https://galaxy.ansible.com/ansible-community/consul/
BSD 2-Clause "Simplified" License
450 stars 313 forks source link

Specify virtual env path when using a virtual env. #564

Closed bastienwirtz closed 7 months ago

bastienwirtz commented 1 year ago

In order to properly load the environment when using a virtual env, the virtualenv parameter must be specified.

This patch fix the the externally-managed-environment error (since PEP 668 has been adopted recently):

TASK [ansible-consul : Install netaddr dependency on controlling host (virtualenv)] *****************************************************************************************************************************************************************************************************
fatal: [consul-lab01 -> 127.0.0.1]: FAILED! => {"changed": false, "cmd": ["/usr/bin/python", "-m", "pip.__main__", "install", "netaddr"], "msg": "\n:stderr: error: externally-managed-environment\n\n× This environment is externally managed\n╰─> To install Python packages system-wide, try 'pacman -S\n    python-xyz', where xyz is the package you are trying to\n    install.\n    \n    If you wish to install a non-Arch-packaged Python package,\n    create a virtual environment using 'python -m venv path/to/venv'.\n    Then use path/to/venv/bin/python and path/to/venv/bin/pip.\n    \n    If you wish to install a non-Arch packaged Python application,\n    it may be easiest to use 'pipx install xyz', which will manage a\n    virtual environment for you. Make sure you have python-pipx\n    installed via pacman.\n\nnote: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.\nhint: See PEP 668 for the detailed specification.\n"}

Also, is_virutalenv was renamed to virtualenv, as it's not a boolean (could also be virtualenv_path and moved to the path section of the variable defaults?)

bastienwirtz commented 1 year ago

No worries @nre-ableton, thanks for the review !

bastienwirtz commented 7 months ago

Updated @nre-ableton