Skip to content

Update for Ansible NetBox Collection to Support 'role' Field Change #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

NetOpsChic
Copy link

Issue

When attempting to add a new device into NetBox via Ansible, the task fails due to a change in NetBox v3.6.0. In this version, the device_role field on the Device model has been renamed to role. For backward compatibility the field name "device_role" still exist.

This change has not been reflected in the latest Ansible Galaxy NetBox Collection. As a result, when trying to use the updated "role" field, the module throws an error, insisting on using the "device_role" key.

NetBox version: v3.6.3
netbox.netbox collection version: v3.14.0
netbox.netbox version: v0.1.0

Behavior

While adding new device to NetBox via Ansible its throws the following error
fatal: [localhost]: FAILED! => {"changed": false, "msg": "{"role":["This field is required."]}"}

Discussion: Benefits

Ensures compatibility with NetBox v3.6.0 and later.
Prevents unnecessary errors and confusion related to the changed field name.

Changes to the Documentation

- name: "Test NetBox modules"
  connection: local
  hosts: localhost
  gather_facts: False

  tasks:
    - name: Create device within NetBox with only required information
      netbox.netbox.netbox_device:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Test Device
          device_type: C9410R
          role: Core Switch # device_role to role
          site: Main
        state: present

    - name: Create device within NetBox with empty string name to generate UUID
      netbox.netbox.netbox_device:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: ""
          device_type: C9410R
          role: Core Switch # device_role to role
          site: Main
        state: present
   - name: Delete device within netbox
      netbox.netbox.netbox_device:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Test Device
        state: absent

Proposed Release Note Entry

Update netbox.netbox.netbox_device to support 'role' Field Change

  • [x ] I have read the comments and followed the CONTRIBUTING.md.
  • [x ] I have explained my PR according to the information in the comments or in a linked issue.
  • [x ] My PR targets the devel branch.

@NetOpsChic NetOpsChic changed the title bugfix for Ansible NetBox Collection to Support 'role' Field Change Update for Ansible NetBox Collection to Support 'role' Field Change Oct 30, 2023
Copy link
Contributor

@sc68cal sc68cal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of #1066

@rodvand rodvand closed this Oct 30, 2023
@NetOpsChic NetOpsChic deleted the bugfix_device_role branch October 30, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants