diff --git a/files/ansible-playbooks/sot-updater.yml b/files/ansible-playbooks/sot-updater.yml index 0f95df7..08d762a 100644 --- a/files/ansible-playbooks/sot-updater.yml +++ b/files/ansible-playbooks/sot-updater.yml @@ -288,6 +288,20 @@ nb_custom_fields_current: {} changed_when: false + - name: NB baseline | Read id and custom_fields (fields) + delegate_to: localhost + uri: + url: "{{ netbox_url }}/api/dcim/devices/?name={{ inventory_hostname }}&fields=id,custom_fields" + method: GET + headers: + Authorization: "Token {{ netbox_token }}" + return_content: true + status_code: 200 + timeout: 10 + register: nb_cf_lookup + failed_when: false + changed_when: false + # NOTE: this task must exist above (keep your existing one): # - name: NB baseline | Read id and custom_fields (fields) # delegate_to: localhost @@ -303,8 +317,8 @@ }} set_fact: nb_baseline_ok: true - nb_device_id: "{{ nb_cf_json_local.results[0].id | default('') }}" - nb_custom_fields_current: "{{ nb_cf_json_local.results[0].custom_fields | default({}) }}" + nb_device_id: "{{ (nb_cf_json_local.results | default([]) | first | default({})).id | default('') }}" + nb_custom_fields_current: "{{ (nb_cf_json_local.results | default([]) | first | default({})).custom_fields | default({}) }}" changed_when: false failed_when: false