This commit is contained in:
2025-11-04 09:43:14 +02:00
parent 44c3965494
commit 1d314d96af

View File

@@ -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(['<no stdout>'])) }}"
- "stderr_lines:"
- "{{ (nb_preflight.stderr_lines | default(['<no stderr>'])) }}"
- "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: