From 1d314d96afaeed218610f9523b9548374e79f0f4 Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 4 Nov 2025 09:43:14 +0200 Subject: [PATCH] 09:43 --- files/ansible-playbooks/sot-updater.yml | 58 +++++++++++++++++-------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/files/ansible-playbooks/sot-updater.yml b/files/ansible-playbooks/sot-updater.yml index 6701f79..a39c40b 100644 --- a/files/ansible-playbooks/sot-updater.yml +++ b/files/ansible-playbooks/sot-updater.yml @@ -38,34 +38,56 @@ control_queue: "{{ lookup('env','CONTROLQUEUE') | default('queue_controls', true) }}" pre_tasks: - - name: "NB preflight | Run netbox_one_device.py for {{ inventory_hostname }} (chatty)" + - name: "NB preflight | Verify script exists" delegate_to: localhost - environment: - PYTHONUNBUFFERED: "1" # make Python flush immediately - args: - chdir: "/opt/containers/ansible-worker/app" - shell: | - set -o pipefail - python3 netbox_one_device.py "{{ inventory_hostname }}" --chatty 2>&1 - register: nb_preflight - changed_when: false # informational only - failed_when: false # soft-fail, keep going + ansible.builtin.stat: + path: "/opt/containers/ansible-worker/app/nb_onedevice_update.py" + register: nb_script - - name: "NB preflight | Print chatty output" + - name: "NB preflight | Abort softly if script missing (path typo?)" delegate_to: localhost ansible.builtin.debug: - msg: >- - {{ - (nb_preflight.stdout_lines | default([])) | - map('regex_replace', '^(.*)$', 'NB | \\1') | - list - }} + msg: + - "NB preflight skipped: /opt/containers/ansible-worker/app/nb_onedevice_update.py not found." + - "Tip: adjust chdir/path or script name." + when: not nb_script.stat.exists + + - name: "NB preflight | Run nb_onedevice_update.py for {{ inventory_hostname }} (chatty)" + when: nb_script.stat.exists + delegate_to: localhost + environment: + PYTHONUNBUFFERED: "1" # flush prints immediately + # Add any env your script needs here, e.g.: + # NB_URL: "{{ lookup('env','NB_URL') | default('', true) }}" + # NB_TOKEN: "{{ lookup('env','NB_TOKEN') | default('', true) }}" + args: + chdir: "/opt/containers/ansible-worker/app" + executable: /bin/bash + shell: | + set -o pipefail + python3 -u nb_onedevice_update.py "{{ inventory_hostname }}" --chatty 2>&1 + register: nb_preflight + changed_when: false # informational + failed_when: false # soft-fail, keep going + + - name: "NB preflight | Show results" + when: nb_script.stat.exists + delegate_to: localhost + ansible.builtin.debug: + msg: + - "rc={{ nb_preflight.rc }}" + - "stdout_lines:" + - "{{ (nb_preflight.stdout_lines | default([''])) }}" + - "stderr_lines:" + - "{{ (nb_preflight.stderr_lines | default([''])) }}" + - "raw stdout (joined): {{ nb_preflight.stdout | default('') | trim }}" - name: "NB preflight | Pause 1s" delegate_to: localhost ansible.builtin.pause: seconds: 1 + tasks: - name: "⚙️ Start | Dev1 banner → tunnel/auth → Dev2 firmux (telemetry mode)" debug: