瀏覽代碼

fix: suppress Python interpreter discovery warning with auto_silent

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kotoyuuko 3 周之前
父節點
當前提交
b7046afbdf

+ 1 - 1
group_vars/all.yml.example

@@ -10,4 +10,4 @@ base_packages:
 
 ssh_port: "{{ ansible_port | default(22) }}"
 
-ansible_python_interpreter: auto
+ansible_python_interpreter: auto_silent

+ 2 - 0
openspec/changes/archive/2026-04-22-fix-python-interpreter-warning/.openspec.yaml

@@ -0,0 +1,2 @@
+schema: spec-driven
+created: 2026-04-22

+ 27 - 0
openspec/changes/archive/2026-04-22-fix-python-interpreter-warning/design.md

@@ -0,0 +1,27 @@
+## Context
+
+The project previously added `ansible_python_interpreter: auto` in `group_vars/all.yml` to handle hosts where Python might not be at the default path. This works correctly — Ansible discovers the interpreter and uses it. However, `auto` mode logs a `[WARNING]` on every host about the discovered interpreter potentially changing in the future, cluttering playbook output.
+
+Ansible provides two auto-discovery modes:
+- `auto` — discovers interpreter, logs a warning about future instability
+- `auto_silent` — identical discovery logic, suppresses the warning
+
+## Goals / Non-Goals
+
+**Goals:**
+- Suppress the Python interpreter discovery warning on all hosts
+- Maintain automatic interpreter discovery behavior
+
+**Non-Goals:**
+- Pinning to a specific Python path (would break portability across different OS versions)
+- Changing Python version or installation method
+
+## Decisions
+
+**Use `auto_silent` instead of a hardcoded path.**
+
+`auto_silent` preserves the same discovery logic as `auto` but suppresses the warning. The alternative — hardcoding `/usr/bin/python3` or `/usr/bin/python3.13` — would break when hosts run different Python versions or when Python is upgraded.
+
+## Risks / Trade-offs
+
+**[Silenced warnings may hide a real interpreter change]** → Acceptable. The bootstrap play already ensures Python 3 is installed. If a second interpreter appears, Ansible's discovery order is deterministic and well-documented. The warning is informational, not actionable.

+ 22 - 0
openspec/changes/archive/2026-04-22-fix-python-interpreter-warning/proposal.md

@@ -0,0 +1,22 @@
+## Why
+
+Running playbooks produces a `[WARNING]` on every host about the discovered Python interpreter (`/usr/bin/python3.13`) potentially changing if another interpreter is installed later. This is noisy and obscures real warnings. The current `ansible_python_interpreter: auto` setting performs discovery correctly but logs a warning each time — Ansible provides `auto_silent` specifically to suppress this.
+
+## What Changes
+
+- Change `ansible_python_interpreter` from `auto` to `auto_silent` in `group_vars/all.yml` to suppress the interpreter discovery warning while retaining the same auto-discovery behavior.
+
+## Capabilities
+
+### New Capabilities
+
+(none)
+
+### Modified Capabilities
+
+- `python-bootstrap`: The interpreter discovery mode changes from `auto` to `auto_silent`, suppressing the discovery warning while preserving identical behavior.
+
+## Impact
+
+- `group_vars/all.yml`: Single-line change to `ansible_python_interpreter` value.
+- No behavioral change — `auto_silent` performs the same discovery logic as `auto`, just without the warning.

+ 18 - 0
openspec/changes/archive/2026-04-22-fix-python-interpreter-warning/specs/python-bootstrap/spec.md

@@ -0,0 +1,18 @@
+## MODIFIED Requirements
+
+### Requirement: Python 3 is bootstrapped on all managed hosts before module execution
+A pre-task play SHALL run before any other plays in `site.yml` that installs `python3` on all hosts using the `raw` module. This play SHALL set `gather_facts: false` to avoid triggering the setup module. The install command SHALL be idempotent (safe to re-run on hosts where Python is already installed). The `ansible_python_interpreter` SHALL be set to `auto_silent` in `group_vars/all.yml` to enable automatic interpreter discovery without emitting warnings.
+
+#### Scenario: Host without Python 3
+- **WHEN** Ansible runs against a host that does not have Python 3 installed
+- **THEN** the raw task installs `python3` via `apt-get install -y python3`
+- **THEN** subsequent plays can use standard Ansible modules
+
+#### Scenario: Host already has Python 3
+- **WHEN** Ansible runs against a host that already has Python 3 installed
+- **THEN** the raw task completes successfully without changing the system
+- **THEN** subsequent plays run normally
+
+#### Scenario: Interpreter discovery runs silently
+- **WHEN** Ansible discovers the Python interpreter on any managed host
+- **THEN** no `[WARNING]` about interpreter discovery SHALL be emitted in playbook output

+ 7 - 0
openspec/changes/archive/2026-04-22-fix-python-interpreter-warning/tasks.md

@@ -0,0 +1,7 @@
+## 1. Update interpreter setting
+
+- [x] 1.1 Change `ansible_python_interpreter` from `auto` to `auto_silent` in `group_vars/all.yml`
+
+## 2. Verify
+
+- [x] 2.1 Run playbook with `--check` and confirm no `[WARNING]` about interpreter discovery appears in output

+ 5 - 1
openspec/specs/python-bootstrap/spec.md

@@ -1,7 +1,7 @@
 ## ADDED Requirements
 
 ### Requirement: Python 3 is bootstrapped on all managed hosts before module execution
-A pre-task play SHALL run before any other plays in `site.yml` that installs `python3` on all hosts using the `raw` module. This play SHALL set `gather_facts: false` to avoid triggering the setup module. The install command SHALL be idempotent (safe to re-run on hosts where Python is already installed).
+A pre-task play SHALL run before any other plays in `site.yml` that installs `python3` on all hosts using the `raw` module. This play SHALL set `gather_facts: false` to avoid triggering the setup module. The install command SHALL be idempotent (safe to re-run on hosts where Python is already installed). The `ansible_python_interpreter` SHALL be set to `auto_silent` in `group_vars/all.yml` to enable automatic interpreter discovery without emitting warnings.
 
 #### Scenario: Host without Python 3
 - **WHEN** Ansible runs against a host that does not have Python 3 installed
@@ -12,3 +12,7 @@ A pre-task play SHALL run before any other plays in `site.yml` that installs `py
 - **WHEN** Ansible runs against a host that already has Python 3 installed
 - **THEN** the raw task completes successfully without changing the system
 - **THEN** subsequent plays run normally
+
+#### Scenario: Interpreter discovery runs silently
+- **WHEN** Ansible discovers the Python interpreter on any managed host
+- **THEN** no `[WARNING]` about interpreter discovery SHALL be emitted in playbook output