From 4e7a78810abb3468120712589f854a7425f09f54 Mon Sep 17 00:00:00 2001 From: Semaphore Date: Wed, 11 Mar 2026 10:39:34 -0700 Subject: [PATCH] =?UTF-8?q?Add=20Python=20bootstrap=20task=20=E2=80=94=20a?= =?UTF-8?q?uto-installs=20python3=20on=20Alpine/Debian=20before=20gather?= =?UTF-8?q?=5Ffacts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playbooks/linux_patch.yml | 6 ++++++ playbooks/site_preflight.yml | 6 ++++++ roles/preflight/tasks/bootstrap.yml | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 roles/preflight/tasks/bootstrap.yml diff --git a/playbooks/linux_patch.yml b/playbooks/linux_patch.yml index 8e55a7c..ce13c64 100644 --- a/playbooks/linux_patch.yml +++ b/playbooks/linux_patch.yml @@ -1,4 +1,10 @@ --- +- name: Bootstrap — ensure Python is available + hosts: linux_hosts + gather_facts: false + tasks: + - ansible.builtin.import_tasks: ../roles/preflight/tasks/bootstrap.yml + - name: Linux patching hosts: linux_hosts gather_facts: true diff --git a/playbooks/site_preflight.yml b/playbooks/site_preflight.yml index e216cff..d577197 100644 --- a/playbooks/site_preflight.yml +++ b/playbooks/site_preflight.yml @@ -1,4 +1,10 @@ --- +- name: Bootstrap — ensure Python is available + hosts: all + gather_facts: false + tasks: + - ansible.builtin.import_tasks: ../roles/preflight/tasks/bootstrap.yml + - name: Pre-flight safety checks hosts: all gather_facts: true diff --git a/roles/preflight/tasks/bootstrap.yml b/roles/preflight/tasks/bootstrap.yml new file mode 100644 index 0000000..d9a389a --- /dev/null +++ b/roles/preflight/tasks/bootstrap.yml @@ -0,0 +1,18 @@ +--- +# Runs before gather_facts using raw commands — no Python required +- name: Check if python3 is installed + ansible.builtin.raw: which python3 || echo "missing" + register: python_check + changed_when: false + +- name: Install python3 on Alpine (raw — no Python needed) + ansible.builtin.raw: apk add --no-cache python3 + when: "'missing' in python_check.stdout" + changed_when: true + +- name: Install python3 on Debian/Ubuntu (raw — no Python needed) + ansible.builtin.raw: apt-get install -y python3 + when: + - "'missing' in python_check.stdout" + - ansible_os_family is not defined or ansible_os_family == 'Debian' + changed_when: true