From 85748918643a0356de045ffd0767e0d58cb2496f Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 28 Oct 2025 09:47:13 +0200 Subject: [PATCH] 0947 --- files/ansible-playbooks/sot-updater.yml | 86 ++++++------------------- 1 file changed, 18 insertions(+), 68 deletions(-) diff --git a/files/ansible-playbooks/sot-updater.yml b/files/ansible-playbooks/sot-updater.yml index 5475e56..2c5e64f 100644 --- a/files/ansible-playbooks/sot-updater.yml +++ b/files/ansible-playbooks/sot-updater.yml @@ -218,49 +218,26 @@ debug: msg: "Dev1 fw_version {{ dev1_fw_clean | default('N/A') }}" - # ---- Defensive deep grep (catches fw_version anywhere in hostvars JSON) - - name: Hostvars JSON (for deep grep) + # ---- read NetBox current custom field for Dev1 and conditionally publish ---- + - name: NetBox | Current custom fw_version set_fact: - _hostvars_json: "{{ hostvars[inventory_hostname] | to_nice_json }}" + nb_fw_version: "{{ (hostvars[inventory_hostname].custom_fields.fw_version | default('')) }}" - - name: NetBox | Current custom fw_version (coalesced) - set_fact: - nb_fw_version: >- - {{ - ( - hostvars[inventory_hostname].custom_fields.fw_version - | default('', true) - ) - or - ( - hostvars[inventory_hostname].nb_custom_fields.fw_version - | default('', true) - ) - or - ( - hostvars[inventory_hostname].custom_fields_fw_version - | default('', true) - ) - or - ( - hostvars[inventory_hostname].fw_version - | default('', true) - ) - or - ( - _hostvars_json | regex_search('\"fw_version\"\\s*:\\s*\"([^\"]*)\"', '\\1') - | default('', true) - ) - | string | trim - }} + # >>> NEW ONLY: explicit comparison debug (before any update decision) + - name: Dev1 | Compare local vs inventory (debug) + delegate_to: localhost + debug: + msg: + - "Dev1 collected fw='{{ dev1_fw_clean | default('') }}'" + - "Inventory fw (hostvars.custom_fields.fw_version)='{{ (hostvars[inventory_hostname].custom_fields.fw_version | default('')) }}'" - name: Dev1 | Version matches NetBox → skip update - when: (dev1_fw_clean | default('') | trim) == (nb_fw_version | default('') | trim) + when: (dev1_fw_clean | default('')) == (nb_fw_version | default('')) debug: msg: "version matches, we'll skip Netbox update" - name: Publish Dev1 fw_version - when: (dev1_fw_clean | default('') | trim) != (nb_fw_version | default('') | trim) + when: (dev1_fw_clean | default('')) != (nb_fw_version | default('')) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost | urlencode }}/{{ rmq_exchange | urlencode }}/publish" @@ -355,45 +332,18 @@ | trim }} - # ---- Defensive deep grep (catches indoor_fwver anywhere in hostvars JSON) - - name: NetBox | Current custom indoor_fwver (coalesced) + # ---- read NetBox current custom field for Dev2 and conditionally publish ---- + - name: NetBox | Current custom indoor_fwver set_fact: - nb_indoor_fwver: >- - {{ - ( - hostvars[inventory_hostname].custom_fields.indoor_fwver - | default('', true) - ) - or - ( - hostvars[inventory_hostname].nb_custom_fields.indoor_fwver - | default('', true) - ) - or - ( - hostvars[inventory_hostname].custom_fields_indoor_fwver - | default('', true) - ) - or - ( - hostvars[inventory_hostname].indoor_fwver - | default('', true) - ) - or - ( - _hostvars_json | regex_search('\"indoor_fwver\"\\s*:\\s*\"([^\"]*)\"', '\\1') - | default('', true) - ) - | string | trim - }} + nb_indoor_fwver: "{{ (hostvars[inventory_hostname].custom_fields.indoor_fwver | default('')) }}" - name: Dev2 | Version matches NetBox → skip update - when: (indoor_fw_norm | default('') | trim) == (nb_indoor_fwver | default('') | trim) + when: (indoor_fw_norm | default('')) == (nb_indoor_fwver | default('')) debug: msg: "version matches, we'll skip Netbox update" - name: Publish Dev2 indoor_fwver - when: (indoor_fw_norm | default('') | trim) != (nb_indoor_fwver | default('') | trim) + when: (indoor_fw_norm | default('')) != (nb_indoor_fwver | default('')) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost | urlencode }}/{{ rmq_exchange | urlencode }}/publish" @@ -411,7 +361,7 @@ 'inscope_device': (ansible_hostname | default(inventory_hostname)), 'task_name': 'custom_field_set', 'task_add1': 'indoor_fwver', - 'task_result': (indoor_fw_norm if indoor_fw_norm|length>0 else 'unavailable') + 'task_result': (indoor_fw_norm if (indoor_fw_norm|length>0) else 'unavailable') } | to_json }}" payload_encoding: "string" changed_when: false