netbox-community / ansible_modules

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

[Bug]: cannot create custom_fields of type select #1209

Open jhofmueller opened 4 months ago

jhofmueller commented 4 months ago

Ansible NetBox Collection version

v3.17.0

Ansible version

ansible [core 2.14.13]
  config file = /home/jogi/git/dcim/netbox-dev/ansible.cfg
  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 the following playbook on a netbox instance.

- name: Playbook
  hosts: 127.0.0.1
  gather_facts: false
  become: false

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

This is what happens:

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": "{\"error\": \"'NoneType' object has no attribute 'values'\", \"exception\": \"AttributeError\", \"netbox_version\": \"3.7.5\", \"python_version\": \"3.11.4\"}"}

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

Expected Behavior

The custom_field should have been created.

Observed Behavior

An AttributeError exception was raised.

sc68cal commented 4 months ago

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

aopdal commented 2 months ago

This works in 3.19.1. You must split it to first create choice set using netbox_custom_field_choice_set and then create the custom field.