Skip to content

Commit

Permalink
tests: Allow to set Python interpreter to be used by Ansible
Browse files Browse the repository at this point in the history
On some systems it is required or desired to run Ansible with a specific
Python interpreter. This patch allows the selection of the Python binary
to use for the pytest playbook tests by setting the environment variable
IPA_PYTHON_PATH. Set it the the full path of the Python interpreter.
  • Loading branch information
rjeffman committed Jul 20, 2024
1 parent e6ad178 commit e97c0b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ environment variable. For example:
IPA_SSH_PASSWORD=<ipaserver_ssh_password> IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
```

If you want, or ned to to set the Python interpreter to use, you must set `IPA_PYTHON_PATH`
environment variable. For example:

```
IPA_PYTHON_PATH=/usr/bin/python3.14 IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
```

To run a single test use the full path with the following format:

Expand Down
10 changes: 10 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def get_ssh_password():
return os.getenv("IPA_SSH_PASSWORD")


def get_python_interpreter():
return os.getenv("IPA_PYTHON_PATH")


def get_server_host():
return os.getenv("IPA_SERVER_HOST")

Expand Down Expand Up @@ -97,6 +101,12 @@ def get_inventory_content():
if sshpass:
ipa_server_host += " ansible_ssh_pass=%s" % sshpass

python_interpreter = get_python_interpreter()
if python_interpreter:
ipa_server_host += (
" ansible_python_interpreter=%s" % python_interpreter
)

lines = [
"[ipaserver]",
ipa_server_host,
Expand Down

0 comments on commit e97c0b3

Please sign in to comment.