netbox-community / ansible_modules

NetBox modules for Ansible using Ansible Collections
GNU General Public License v3.0
330 stars 213 forks source link

[Bug]: Altering custom_field fails when ui_visibility: is used #1210

Open jhofmueller opened 6 months ago

jhofmueller commented 6 months ago

Ansible NetBox Collection version

v3.17.0

Ansible version

ansible [core 2.14.13]
  config file = None
  configured module search path = ['/home/jogi/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/jogi/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.8 (main, Feb  7 2024, 21:52:08) [GCC 13.2.0] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True

NetBox version

v3.7.5

Python version

3.11

Steps to Reproduce

Run this playbook twice:

  hosts: 127.0.0.1
  gather_facts: false
  become: false
  connection: local

  tasks:
    - name: Create one custom field
      netbox.netbox.netbox_custom_field:
        netbox_url: NETBOX_URI
        netbox_token: NETBOX_TOKEN
        data:
          content_types:
            - ipam.ipaddress
          default: two
          description: description
          filter_logic: loose
          group_name: group
          label: dummy
          name: dummy
          required: false
          search_weight: 1
          type: text
          ui_visibility: read-write
        state: present

The first run works as expected, creating the custom variable.

PLAY [Playbook :: Install/Upgrade Docker Containers for Netbox] *****************************************************************************************************************************

TASK [Create one custom field] **************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP **********************************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

The second run however fails:

PLAY [Playbook :: Install/Upgrade Docker Containers for Netbox] *****************************************************************************************************************************

TASK [Create one custom field] **************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3.11"}, "changed": false, "msg": "ui_visibility does not exist on existing object. Check to make sure valid field."}

PLAY RECAP **********************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Expected Behavior

I expected either an unchanged message or a change message in case something was changed.

Observed Behavior

ui_visibility does not exist on existing object

sc68cal commented 6 months ago

I believe we have merged code that fixes this, but we have not cut a new release yet.

ccieblogger commented 5 months ago

Hello, we are seeing the same behavior. Initial run works but seems to ignore ui_visibility value and just sets the default for the object. Subsequent runs fail and display the following error.

failed: [localhost] (item={'name': 'SiteID', 'description': 'Defines the site ID', 'content_types': ['dcim.site'], 'type': 'integer', 'ui_visibility': 'read-only', 'ui_editable': False, 'required': True}) => changed=false ansible_loop_var: item item: content_types:

bluikko commented 4 months ago

This seems to be possibly a duplicate of #1135. Unfortunately I have had to put the associated PR on hold since pynetbox has not seen updates in half a year and we are re-evaluating the use of NetBox vs. a fork.

Andres1357 commented 2 months ago

Hi, curious if this fix is back on the roadmap now that pynetbox has a new release?