ansible_modules icon indicating copy to clipboard operation
ansible_modules copied to clipboard

[Bug]: Updating custom fields with netbox.netbox.netbox_device_interface always generate changes

Open SteveRodrigue opened this issue 3 years ago • 6 comments

SOFTWARE VERSIONS
Ansible: ansible 2.10.11
Netbox: v2.11.6
Collection: netbox.netbox:3.1.1
SUMMARY

If you have more than 1 custom fields in netbox interfaces table and you want to update only 1 field (not all of them), the module always generates a "changed" status.

STEPS TO REPRODUCE
  1. Create any custom field for interfaces in Netbox. Use the module to update that field. Correct status is reported.
  2. Create a second custom field for interfaces in Netbox. Rerun the same task to update the first field (and not the newly created one). The module will always report a changed status.
  3. Destroy the second field and rerun the task: back to normal status behaviour.
    - name: Update a custom field
      netbox.netbox.netbox_device_interface:
        netbox_url: "{{ netbox_url }}"
        netbox_token: "{{ netbox_api_token_rw }}"
        data:
          device: "{{ inventory_hostname }}"
          name: "{{ interface_name }}"
          type: "{{ interface_type }}"
          custom_fields:
            test_field: "If more than one custom field exists, this task will always have a changed status."
        state: present

EXPECTED RESULTS

In theory, only the affected custom field should be checked/compared. If other custom fields exists, they should be ignored when the "diff/check" is done in the module.

ACTUAL RESULTS

Task changed but should not on the second run where we haven't changed anything in that custom field.

SteveRodrigue avatar Aug 27 '21 17:08 SteveRodrigue

I have the same issue without custom fields. The module seems to compare pre and post data after changing the last_updated field. Which always is a change. So everytime I run my playbook to update interfaces of devices, a change is pushed to netbox. Steve, can you verify this? If this is a different issue, I'd gladly open my own issue. :-)

image

DZ945brH avatar Nov 05 '21 09:11 DZ945brH

+1 on this.

I have the same issue when using custom fields on a device object. I was hoping to use the Ansible module to keep track of Cisco IOS software versions in a custom field but every time it runs, it generates a blank changelog.

Running the playbook with debugging enabled, my issue appears to be because Ansible removes other custom fields that are 'null' in the diff, i.e.

"changed": true,
  "msg": "device mydevice updated",
  "diff": {
    "before": {
      "custom_fields": {
        "customfield1": null,
        "customfield2": null,
        "sw_version": "1.1.1"
      }
    },
    "after": {
      "custom_fields": {
        "sw_version": "1.1.1"
      }
    }
  },

jasonyates avatar Mar 07 '22 09:03 jasonyates

hello any update on this? Thanks in advance BR Victor

bapi25 avatar Apr 21 '22 19:04 bapi25

+1

I have the same issue with the virtual machine module, and all the most recent versions (Netbox v3.2.1, ansible-core v2.11.5, Ansible collection v3.7.1, pynetbox v6.6.2).

In addition, the "changed" status is fired also if I forcefully add all the other custom fields with null values: in this case the "diff" shows that the null fields have been added/created (which is not correct since they are null by default).

fabricat avatar Apr 27 '22 14:04 fabricat

Was this ever working for you correctly? If so what combo of netbox, ansible collection, and pynetbox were you using?

ryanmerolle avatar Apr 27 '22 14:04 ryanmerolle

@ryanmerolle it did not ever work ok for me. However I've started using Netbox just a few months ago.

fabricat avatar Apr 27 '22 17:04 fabricat

Should be fixed in https://github.com/netbox-community/ansible_modules/pull/839

rodvand avatar Oct 26 '22 20:10 rodvand