diff mbox

[0/2] python interpreter in ansible.cfg

Message ID 20250404-python-interpreter-v1-0-04783b627ce7@samsung.com (mailing list archive)
State New
Headers show

Commit Message

Daniel Gomez April 4, 2025, 8:01 p.m. UTC
This adds support for the Ansible Python Interpreter [1] in Kconfig
and cli. Instead of setting the interpreter individually for every
task/target, just set it globally with the Ansible variable dedicated
for it (interpreter_python).

Set the default interpreter to auto_silent to silent the warning. From
documentation [2]:
"The fallback behavior will issue a warning that the interpreter
should be set explicitly (since interpreters installed later may change
which one is used). This warning behavior can be disabled by setting
auto_silent or auto_legacy_silent"

'auto_silent' will prevent this warning:
  TASK [Gathering Facts]
  
  [started TASK: Gathering Facts on localhost]
  Warning: : Platform linux on host localhost is using the discovered
  Python
  ok: [localhost]
  
  interpreter at /usr/bin/python3.13, but future installation of another
  Python interpreter could change the meaning of that path. See
  
  https://docs.ansible.com/ansible-
  core/2.18/reference_appendices/interpreter_discovery.html for more
  information.
  https://docs.ansible.com/ansible-core/2.18/reference_appendices/
  interpreter_discovery.html

In addition, this allows setting a custom interpreter if a specific
distribution requires it, such as NixOS:

[1]
https://docs.ansible.com/ansible-core/2.18/reference_appendices/interpreter_discovery.html
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#interpreter-python

[2]
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#interpreter-python-fallback

To: Daniel Gomez <da.gomez@samsung.com>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: kdevops@lists.linux.dev
Cc: Daniel Gomez <da.gomez@kernel.org>

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
Daniel Gomez (2):
      ansible_cfg: add python interpreter support
      Makefile: remove ansible_python_interpreter

 Makefile                                           |  2 -
 Makefile.build_qemu                                |  4 --
 Makefile.hypervisor-tunings                        |  1 -
 Makefile.kdevops                                   | 21 +++----
 Makefile.linux-mirror                              |  2 -
 Makefile.postfix                                   |  1 -
 kconfigs/Kconfig.ansible_cfg                       | 64 ++++++++++++++++++++++
 playbooks/roles/ansible_cfg/defaults/main.yml      |  1 +
 .../roles/ansible_cfg/templates/ansible.cfg.j2     |  1 +
 scripts/archive.Makefile                           |  1 -
 scripts/dynamic-pci-kconfig.Makefile               |  3 +-
 scripts/guestfs.Makefile                           | 14 ++---
 scripts/install-menuconfig-deps.Makefile           |  1 -
 scripts/journal-server.Makefile                    |  3 +-
 scripts/kconfig-ansible.Makefile                   |  1 +
 scripts/systemd-timesync.Makefile                  |  3 +-
 scripts/terraform.Makefile                         |  8 +--
 scripts/vagrant.Makefile                           |  6 +-
 18 files changed, 86 insertions(+), 51 deletions(-)
---
base-commit: 41edfaca90249f4e7bd975a906f64340460d3dbf
change-id: 20250402-python-interpreter-cbb06a40c8ff

Best regards,

Comments

Luis Chamberlain April 4, 2025, 11:39 p.m. UTC | #1
On Fri, Apr 04, 2025 at 08:01:14PM +0000, Daniel Gomez wrote:
> This adds support for the Ansible Python Interpreter [1] in Kconfig
> and cli. Instead of setting the interpreter individually for every
> task/target, just set it globally with the Ansible variable dedicated
> for it (interpreter_python).
> 
> Set the default interpreter to auto_silent to silent the warning. From
> documentation [2]:
> "The fallback behavior will issue a warning that the interpreter
> should be set explicitly (since interpreters installed later may change
> which one is used). This warning behavior can be disabled by setting
> auto_silent or auto_legacy_silent"
> 
> 'auto_silent' will prevent this warning:
>   TASK [Gathering Facts]
>   
>   [started TASK: Gathering Facts on localhost]
>   Warning: : Platform linux on host localhost is using the discovered
>   Python
>   ok: [localhost]
>   
>   interpreter at /usr/bin/python3.13, but future installation of another
>   Python interpreter could change the meaning of that path. See
>   
>   https://docs.ansible.com/ansible-
>   core/2.18/reference_appendices/interpreter_discovery.html for more
>   information.
>   https://docs.ansible.com/ansible-core/2.18/reference_appendices/
>   interpreter_discovery.html
> 
> In addition, this allows setting a custom interpreter if a specific
> distribution requires it, such as NixOS:

Nice!

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>

  Luis
diff mbox

Patch

diff --git a/kconfigs/Kconfig.ansible_cfg b/kconfigs/Kconfig.ansible_cfg
index 0c29300..9172e42 100644
--- a/kconfigs/Kconfig.ansible_cfg
+++ b/kconfigs/Kconfig.ansible_cfg
@@ -116,7 +116,7 @@  menu "Ansible Python Interpreter"
 choice
        prompt "Ansible Python Interpreter"
        default ANSIBLE_CFG_INTERPRETER_PYTHON_AUTO if !ANSIBLE_CFG_INTERPRETER_PYTHON_SET_BY_CLI
-       default ANSIBLE_CFG_INTERPRETER_PYTHON_CUSTOM if ANSIBLE_CFG_INTERPRETER_PYTHON_SET_BY_CLI
+       default ANSIBLE_CFG_INTERPRETER_PYTHON_CUSTOM if ANSIBLE_CFG_INTERPRETER_PYTHON_SET_BY_CLI || DISTRO_NIXOS

 config ANSIBLE_CFG_INTERPRETER_PYTHON_AUTO
        bool "Ansible Python Interpreter: Auto"
@@ -151,6 +151,7 @@  config ANSIBLE_CFG_INTERPRETER_PYTHON_CUSTOM_NAME
        string "Custom Ansible Python Interpreter Name"
        default $(shell, ./scripts/append-makefile-vars.sh $(ANSIBLE_CFG_INTERPRETER_PYTHON)) if ANSIBLE_CFG_INTERPRETER_PYTHON_SET_BY_CLI
        default "/usr/bin/python3" if !ANSIBLE_CFG_INTERPRETER_PYTHON_SET_BY_CLI
+       default "/usr/local/env python3" if !ANSIBLE_CFG_INTERPRETER_PYTHON_SET_BY_CLI && DISTRO_NIXOS

 endif # ANSIBLE_CFG_INTERPRETER_PYTHON_CUSTOM