From 9e5fc8f08fec18144a54d0e7d7e977d013714849 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 29 Jun 2016 08:50:22 -0700 Subject: [PATCH] In some cornercases, sys.executable is empty. Work around that by choosing a sensible default path to python and emitting a warning (#16487) Fixes #13585 Fix grammar of warning method --- lib/ansible/inventory/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 7b7238cc759..97de401a6f2 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -479,7 +479,12 @@ class Inventory(object): new_host.vars = self.get_host_vars(new_host) new_host.set_variable("ansible_connection", "local") if "ansible_python_interpreter" not in new_host.vars: - new_host.set_variable("ansible_python_interpreter", sys.executable) + py_interp = sys.executable + if not py_interp: + # sys.executable is not set in some cornercases. #13585 + display.warning('Unable to determine python interpreter from sys.executable. Using /usr/bin/python default. You can correct this by setting ansible_python_interpreter for localhost') + py_interp = '/usr/bin/python' + new_host.set_variable("ansible_python_interpreter", py_interp) self.get_group("ungrouped").add_host(new_host) return new_host