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
This commit is contained in:
Toshio Kuratomi 2016-06-29 08:50:22 -07:00 committed by Toshio Kuratomi
parent e826d3c7d7
commit 9e5fc8f08f

View file

@ -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