From f5b82755fdbb9bc2a79156851dac83bd2fe0b538 Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 28 Oct 2025 09:35:07 +0200 Subject: [PATCH] 0935 --- files/ansible-playbooks/sot-updater.yml | 60 +++++++++++++++++++++---- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/files/ansible-playbooks/sot-updater.yml b/files/ansible-playbooks/sot-updater.yml index fb133ed..0c4dfba 100644 --- a/files/ansible-playbooks/sot-updater.yml +++ b/files/ansible-playbooks/sot-updater.yml @@ -218,18 +218,40 @@ debug: msg: "Dev1 fw_version {{ dev1_fw_clean | default('N/A') }}" - # ---- NEW: read NetBox current custom field for Dev1 and conditionally publish ---- + # ---- Coalesced read of NetBox custom field for Dev1 (handles different inventory shapes) - name: NetBox | Current custom fw_version set_fact: - nb_fw_version: "{{ (hostvars[inventory_hostname].custom_fields.fw_version | default('')) }}" + 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) + ) + | string | trim + }} - name: Dev1 | Version matches NetBox → skip update - when: (dev1_fw_clean | default('')) == (nb_fw_version | default('')) + when: (dev1_fw_clean | default('') | trim) == (nb_fw_version | default('') | trim) debug: msg: "version matches, we'll skip Netbox update" - name: Publish Dev1 fw_version - when: (dev1_fw_clean | default('')) != (nb_fw_version | default('')) + when: (dev1_fw_clean | default('') | trim) != (nb_fw_version | default('') | trim) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost | urlencode }}/{{ rmq_exchange | urlencode }}/publish" @@ -324,18 +346,40 @@ | trim }} - # ---- NEW: read NetBox current custom field for Dev2 and conditionally publish ---- + # ---- Coalesced read of NetBox custom field for Dev2 (handles different inventory shapes) - name: NetBox | Current custom indoor_fwver set_fact: - nb_indoor_fwver: "{{ (hostvars[inventory_hostname].custom_fields.indoor_fwver | default('')) }}" + 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) + ) + | string | trim + }} - name: Dev2 | Version matches NetBox → skip update - when: (indoor_fw_norm | default('')) == (nb_indoor_fwver | default('')) + when: (indoor_fw_norm | default('') | trim) == (nb_indoor_fwver | default('') | trim) debug: msg: "version matches, we'll skip Netbox update" - name: Publish Dev2 indoor_fwver - when: (indoor_fw_norm | default('')) != (nb_indoor_fwver | default('')) + when: (indoor_fw_norm | default('') | trim) != (nb_indoor_fwver | default('') | trim) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost | urlencode }}/{{ rmq_exchange | urlencode }}/publish"