Using virtual environment on target host(s)

Hi folks,

I am wondering if there is a way to use a specific python virtual environment on the target host.

Reason for that is that some modules/collections require non-core python modules, but installing these modules on the host level via pip can break systems python dependencies. (Debian 12 for example explicitly warns from doing so - for good reasons)

Is there an “ansible native” way of executing the ansible built python scripts in a venv? Something like

- name: A task
  venv: /path/to/a/venv
  a.thirdparty.module_with_pip_dependencies:
    parameter_a: 123

If not, where is the right place to discuss this feature (and contribute code later)?

Thanks

Probably simpler to just use PEP 370 – Per user site-packages directory | peps.python.org as a venv needs to be activated, which you can kind of do by specifying the ansible_python_interpreter and setting PYTHONPATH in the environment:.