1236
This commit is contained in:
@@ -1,46 +1,96 @@
|
||||
---
|
||||
- name: WiFiDebug scheduler wrapper
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
# wifidebug-scheduler.yml
|
||||
# Single nbplay invocation:
|
||||
# Phase 1: Cloud -> NetBox sync (via sot-updater-iponly.yml in wrapper mode)
|
||||
# Phase 2: Refresh ansible_host from nb_ip, reset_connection
|
||||
# Phase 3: Run wifidebug17.yml
|
||||
|
||||
|
||||
- hosts: all
|
||||
gather_facts: no
|
||||
vars:
|
||||
rmq_host: "{{ lookup('env','RMQ_HOST') | default('10.210.12.2', true) }}"
|
||||
rmq_port: "{{ lookup('env','RMQ_PORT') | default('15672', true) }}"
|
||||
rmq_user: "{{ lookup('env','RMQ_USER') | default('admin', true) }}"
|
||||
rmq_pass: "{{ lookup('env','RMQ_PASS') | default('change_me', true) }}"
|
||||
rmq_vhost: "{{ lookup('env','RMQ_VHOST') | default('app', true) }}"
|
||||
rmq_exchange: "{{ lookup('env','RMQ_EXCHANGE') | default('controls', true) }}"
|
||||
control_queue: "{{ lookup('env','CONTROLQUEUE') | default('queue_controls', true) }}"
|
||||
tasks: []
|
||||
|
||||
- import_playbook: sot-updater-iponly.yml
|
||||
vars:
|
||||
sot_wrapper_mode: true
|
||||
|
||||
|
||||
- name: Phase 2 | Refresh in-memory target IP after iponly
|
||||
hosts: all
|
||||
gather_facts: no
|
||||
vars:
|
||||
rmq_host: "{{ lookup('env','RMQ_HOST') | default('10.210.12.2', true) }}"
|
||||
rmq_port: "{{ lookup('env','RMQ_PORT') | default('15672', true) }}"
|
||||
rmq_user: "{{ lookup('env','RMQ_USER') | default('admin', true) }}"
|
||||
rmq_pass: "{{ lookup('env','RMQ_PASS') | default('change_me', true) }}"
|
||||
rmq_vhost: "{{ lookup('env','RMQ_VHOST') | default('app', true) }}"
|
||||
rmq_exchange: "{{ lookup('env','RMQ_EXCHANGE') | default('controls', true) }}"
|
||||
control_queue: "{{ lookup('env','CONTROLQUEUE') | default('queue_controls', true) }}"
|
||||
|
||||
tasks:
|
||||
- name: Run sot-updater-iponly in wrapper mode
|
||||
import_playbook: sot-updater-iponly.yml
|
||||
|
||||
- name: Extract NetBox IP from preflight output
|
||||
- name: "Wrapper | Extract nb_ip from nb_onedevice_update.py stdout"
|
||||
vars:
|
||||
_lines: "{{ (nb_preflight.stdout_lines | default([])) | map('regex_replace','\r','') | map('trim') | list }}"
|
||||
_ok_line: "{{ (_lines | select('match','^OK\\s+') | list | last | default('')) }}"
|
||||
_fail_line: "{{ (_lines | select('match','^FAIL\\s+') | list | last | default('')) }}"
|
||||
_ip_raw: "{{ _ok_line | regex_search('([0-9]{1,3}(?:\\.[0-9]{1,3}){3})') | default('') }}"
|
||||
set_fact:
|
||||
nb_ip: >-
|
||||
{{
|
||||
(nb_preflight.stdout_lines
|
||||
| select('match', '^NB_IP=')
|
||||
| list
|
||||
| first
|
||||
| regex_replace('^NB_IP=', '')
|
||||
) | default('')
|
||||
}}
|
||||
when:
|
||||
- nb_preflight is defined
|
||||
- nb_preflight.stdout_lines is defined
|
||||
nb_ip: "{{ _ip_raw }}"
|
||||
nb_ip_ok: "{{ (_ip_raw | length) > 0 }}"
|
||||
nb_ip_err: "{{ _fail_line }}"
|
||||
changed_when: false
|
||||
|
||||
- name: Fail if NetBox IP not found
|
||||
- name: "Wrapper | Abort if nb_ip not available"
|
||||
fail:
|
||||
msg: "NB_IP not found in nb_preflight output, cannot continue wrapper"
|
||||
when:
|
||||
- nb_ip is not defined or nb_ip | length == 0
|
||||
msg: "Wrapper preflight did not produce nb_ip. FAIL line: {{ nb_ip_err | default('') }}"
|
||||
when: not nb_ip_ok
|
||||
|
||||
- name: Override ansible_host to NetBox IP
|
||||
- name: "Wrapper | Debug before ansible_host override"
|
||||
debug:
|
||||
msg:
|
||||
- "inventory_hostname={{ inventory_hostname }}"
|
||||
- "ansible_host(before)={{ ansible_host | default('UNSET') }}"
|
||||
- "ansible_port={{ ansible_port | default('22') }}"
|
||||
- "nb_ip={{ nb_ip | default('UNSET') }}"
|
||||
changed_when: false
|
||||
|
||||
- name: "Wrapper | Update ansible_host to nb_ip"
|
||||
set_fact:
|
||||
ansible_host: "{{ nb_ip }}"
|
||||
changed_when: false
|
||||
|
||||
- name: Reset SSH connection after changing ansible_host
|
||||
- name: "Wrapper | Debug after ansible_host override"
|
||||
debug:
|
||||
msg:
|
||||
- "inventory_hostname={{ inventory_hostname }}"
|
||||
- "ansible_host(after)={{ ansible_host | default('UNSET') }}"
|
||||
- "ansible_port={{ ansible_port | default('22') }}"
|
||||
changed_when: false
|
||||
|
||||
- name: "Wrapper | Reset connection after ansible_host change"
|
||||
meta: reset_connection
|
||||
|
||||
- name: Small pause after reset_connection
|
||||
- name: "Wrapper | Debug after reset_connection"
|
||||
debug:
|
||||
msg:
|
||||
- "inventory_hostname={{ inventory_hostname }}"
|
||||
- "ansible_host(post_reset)={{ ansible_host | default('UNSET') }}"
|
||||
- "ansible_port={{ ansible_port | default('22') }}"
|
||||
changed_when: false
|
||||
|
||||
|
||||
- name: "Wrapper | Pause 2s before next playbook"
|
||||
pause:
|
||||
seconds: 2
|
||||
changed_when: false
|
||||
|
||||
|
||||
- import_playbook: wifidebug17.yml
|
||||
vars:
|
||||
|
||||
Reference in New Issue
Block a user