This commit is contained in:
2026-02-25 18:07:00 +02:00
parent 0b784346f7
commit ab16b95627

View File

@@ -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