From 9c41becc8d499167a48aa5ae77d3e1282964ad61 Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Thu, 15 May 2025 01:25:31 +0200 Subject: Standardize Python interpreter handling This patch ensures that the system Python interpreter is always used during the `bootstrap-servers` phase by setting `ansible_python_interpreter=auto_silent` via `extra_vars`, while the `octavia-certificates` command now explicitly uses the same Python interpreter that was used to invoke the `kolla-ansible` CLI, ensuring compatibility with the local environment. Summary: - The `ansible_python_interpreter` is now dynamically defined in `group_vars/all.yml`, falling back to the system interpreter if no virtualenv is configured. - CLI commands now detect and respect user-specified `ansible_python_interpreter` values via `-e`, and avoid overriding them. - The `bootstrap-servers` command always uses the system Python interpreter by setting `ansible_python_interpreter=auto_silent`, ensuring a clean environment for virtualenv creation. - The `octavia-certificates` command uses the Python interpreter that invoked the `kolla-ansible` CLI, ensuring compatibility with locally installed packages (e.g. cryptography). This improves interpreter handling across commands, especially in environments with custom Python setups or virtual environments. Depends-On: https://review.opendev.org/c/openstack/ansible-collection-kolla/+/949767 Change-Id: I7dc6cf8eda3b1fd48d2000f18b4670a4ef4ce1b4 --- kolla_ansible/cli/commands.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'kolla_ansible') diff --git a/kolla_ansible/cli/commands.py b/kolla_ansible/cli/commands.py index fbfcf02fe..7f9ecde6b 100644 --- a/kolla_ansible/cli/commands.py +++ b/kolla_ansible/cli/commands.py @@ -10,6 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +import sys + from cliff.command import Command from kolla_ansible import ansible @@ -63,6 +65,14 @@ class KollaAnsibleMixin: return verbosity_args def run_playbooks(self, parsed_args, *args, **kwargs): + # If the user knows what they're doing and explicitly sets + # ansible_python_interpreter, respect their choice and avoid + # overriding it by kolla-ansible. + extra = kwargs.get("extra_vars", {}) + for var in getattr(parsed_args, "extra_vars", []) or []: + if var.startswith("ansible_python_interpreter="): + extra.pop("ansible_python_interpreter", None) + break kwargs.update(self._get_verbosity_args()) return ansible.run_playbooks(parsed_args, *args, **kwargs) @@ -153,6 +163,7 @@ class BootstrapServers(KollaAnsibleMixin, Command): extra_vars = {} extra_vars["kolla_action"] = "bootstrap-servers" + extra_vars["ansible_python_interpreter"] = "auto_silent" playbooks = _choose_playbooks(parsed_args, "kolla-host") @@ -199,7 +210,9 @@ class OctaviaCertificates(KollaAnsibleMixin, Command): return parser def take_action(self, parsed_args): - extra_vars = {} + extra_vars = { + "ansible_python_interpreter": sys.executable + } if hasattr(parsed_args, "check_expiry") \ and parsed_args.check_expiry is not None: -- cgit v1.2.3