mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Python interpreter discovery (#50163)
* Python interpreter discovery * No longer blindly default to only `/usr/bin/python` * `ansible_python_interpreter` defaults to `auto_legacy`, which will discover the platform Python interpreter on some platforms (but still favor `/usr/bin/python` if present for backward compatibility). Use `auto` to always use the discovered interpreter, append `_silent` to either value to suppress warnings. * includes new doc utility method `get_versioned_doclink` to generate a major.minor versioned doclink against docs.ansible.com (or some other config-overridden URL) * docs revisions for python interpreter discovery (cherry picked from commit 5b53c0012ab7212304c28fdd24cb33fd8ff755c2) * verify output on some distros, cleanup
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
.. _interpreter_discovery:
|
||||
|
||||
Interpreter Discovery
|
||||
=====================
|
||||
|
||||
Most Ansible modules that execute under a POSIX environment require a Python
|
||||
interpreter on the target host. Unless configured otherwise, Ansible will
|
||||
attempt to discover a suitable Python interpreter on each target host
|
||||
the first time a Python module is executed for that host.
|
||||
|
||||
To control the discovery behavior:
|
||||
|
||||
* for individual hosts and groups, use the ``ansible_python_interpreter`` inventory variable
|
||||
* globally, use the ``interpreter_python`` key in the ``[defaults]`` section of ``ansible.cfg``
|
||||
|
||||
Use one of the following values:
|
||||
|
||||
auto_legacy : (default in 2.8)
|
||||
Detects the target OS platform, distribution, and version, then consults a
|
||||
table listing the correct Python interpreter and path for each
|
||||
platform/distribution/version. If an entry is found, and ``/usr/bin/python`` is absent, uses the discovered interpreter (and path). If an entry
|
||||
is found, and ``/usr/bin/python`` is present, uses ``/usr/bin/python``
|
||||
and issues a warning.
|
||||
This exception provides temporary compatibility with previous versions of
|
||||
Ansible that always defaulted to ``/usr/bin/python``, so if you have
|
||||
installed Python and other dependencies at ``usr/bin/python`` on some hosts,
|
||||
Ansible will find and use them with this setting.
|
||||
If no entry is found, or the listed Python is not present on the
|
||||
target host, searches a list of common Python interpreter
|
||||
paths and uses the first one found; also issues a warning that future
|
||||
installation of another Python interpreter could alter the one chosen.
|
||||
|
||||
auto : (future default in 2.12)
|
||||
Detects the target OS platform, distribution, and version, then consults a
|
||||
table listing the correct Python interpreter and path for each
|
||||
platform/distribution/version. If an entry is found, uses the discovered
|
||||
interpreter.
|
||||
If no entry is found, or the listed Python is not present on the
|
||||
target host, searches a list of common Python interpreter
|
||||
paths and uses the first one found; also issues a warning that future
|
||||
installation of another Python interpreter could alter the one chosen.
|
||||
|
||||
auto_legacy_silent
|
||||
Same as ``auto_legacy``, but does not issue warnings.
|
||||
|
||||
auto_silent
|
||||
Same as ``auto``, but does not issue warnings.
|
||||
|
||||
You can still set ``ansible_python_interpreter`` to a specific path at any
|
||||
variable level (for example, in host_vars, in vars files, in playbooks, etc.).
|
||||
Setting a specific path completely disables automatic interpreter discovery; Ansible always uses the path specified.
|
||||
@@ -39,9 +39,12 @@ command via ``python3``. For example:
|
||||
Using Python 3 on the managed machines with commands and playbooks
|
||||
------------------------------------------------------------------
|
||||
|
||||
* Set the ``ansible_python_interpreter`` configuration option to :command:`/usr/bin/python3`. The
|
||||
``ansible_python_interpreter`` configuration option is usually set as an inventory
|
||||
variable associated with a host or group of hosts:
|
||||
* Ansible will automatically detect and use Python 3 on many platforms that ship with it. To explicitly configure a
|
||||
Python 3 interpreter, set the ``ansible_python_interpreter`` inventory variable at a group or host level to the
|
||||
location of a Python 3 interpreter, such as :command:`/usr/bin/python3`. The default interpreter path may also be
|
||||
set in ``ansible.cfg``.
|
||||
|
||||
.. seealso:: :ref:`interpreter_discovery` for more information.
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
|
||||
Reference in New Issue
Block a user