[Bug]: Untagged Vlan Doesn't Accept Variable

by ADMIN 45 views

Introduction

In this article, we will discuss a bug in the Ansible NetBox Collection version v3.21.0, where untagged VLANs do not accept variables. This issue is observed when trying to update interfaces and untagged VLANs using the netbox.netbox.netbox_device_interface module.

Environment

  • Ansible version: ansible [core 2.17.10]
  • NetBox version: v4.2.5 (cloud)
  • Python version: 3.10

Steps to Reproduce

To reproduce this issue, follow these steps:

  1. Create a playbook with the following tasks:
- name: Update Interface
  netbox.netbox.netbox_device_interface:
    netbox_url: "{{ lookup('ansible.builtin.env', 'NETBOX_API') }}"
    netbox_token: "{{ lookup('ansible.builtin.env', 'NETBOX_TOKEN') }}"
    update_vc_child: true
    data:
      device: "{{ inventory_hostname }}"
      name: "GigabitEthernet1/0/1"
      mode: tagged-all
      untagged_vlan:
        vid: "{{ vlanId|int }}"
        group: "{{ vlanGroupId|int }}"
    state: present
  1. Set the vlanGroupId and vlanId variables to string values:
- set_fact:
    vlanGroupId: "196"
    vlanId: "930"
  1. Run the playbook.

Expected Behavior

The interface should be updated successfully if a valid VLAN group and VID are passed.

Observed Behavior

The playbook fails with the following error:

TASK [Update Interface] ************************************************************************************************
fatal: [TESTDEVICE]: FAILED! => {"changed": false, "msg": "{\"group_id\":[\"“vid” is not a valid value.\"]}"}}

Analysis

The issue is caused by the fact that the netbox.netbox.netbox_device_interface module does not accept variables for the vid and group fields in the untagged_vlan dictionary. This is a bug in the module, as it should be able to accept variables for these fields.

Workaround

To work around this issue, you can pass the VLAN group ID and VID as integers instead of strings. This can be done by using the int filter in Ansible:

- set_fact:
    vlanGroupId: 196
    vlanId: 930

This will allow the playbook to run successfully.

Conclusion

In conclusion, the netbox.netbox.netbox_device_interface module in Ansible NetBox Collection version v3.21.0 has a bug where untagged VLANs do not accept variables. This issue can be worked around by passing the VLAN group ID and VID as integers instead of strings. We hope that this bug will be fixed in future versions of the module.

Future Development

To fix this bug, the netbox.netbox.netbox_device_interface module should be modified to accept variables for the vid and group fields in the untagged_vlan dictionary. This can be done by adding support for variable interpolation in these fieldsRecommendations

  • Upgrade to a newer version of Ansible NetBox Collection: If possible, upgrade to a newer version of Ansible NetBox Collection that has fixed this bug.
  • Use the workaround: If upgrading is not possible, use the workaround by passing the VLAN group ID and VID as integers instead of strings.
  • Submit a bug report: Submit a bug report to the Ansible NetBox Collection developers to report this issue and request that it be fixed.
    Q&A: Bug in Ansible NetBox Collection - Untagged VLAN Doesn't Accept Variable ==========================================================================

Q: What is the bug in Ansible NetBox Collection?

A: The bug in Ansible NetBox Collection is that untagged VLANs do not accept variables. This means that when trying to update interfaces and untagged VLANs using the netbox.netbox.netbox_device_interface module, variables cannot be used for the vid and group fields in the untagged_vlan dictionary.

Q: What are the symptoms of this bug?

A: The symptoms of this bug are:

  • The playbook fails with a fatal error message indicating that the vid is not a valid value.
  • The error message includes a JSON object with a group_id key that contains an array with a single element, which is the error message.

Q: What are the possible causes of this bug?

A: The possible causes of this bug are:

  • A bug in the netbox.netbox.netbox_device_interface module that prevents it from accepting variables for the vid and group fields in the untagged_vlan dictionary.
  • A misconfiguration of the NetBox API or the Ansible NetBox Collection.

Q: How can I work around this bug?

A: To work around this bug, you can pass the VLAN group ID and VID as integers instead of strings. This can be done by using the int filter in Ansible:

- set_fact:
    vlanGroupId: 196
    vlanId: 930

This will allow the playbook to run successfully.

Q: How can I fix this bug?

A: To fix this bug, the netbox.netbox.netbox_device_interface module should be modified to accept variables for the vid and group fields in the untagged_vlan dictionary. This can be done by adding support for variable interpolation in these fields.

Q: What are the implications of this bug?

A: The implications of this bug are:

  • It prevents users from using variables to update interfaces and untagged VLANs using the netbox.netbox.netbox_device_interface module.
  • It may cause issues with automation and scripting that rely on the netbox.netbox.netbox_device_interface module.

Q: How can I report this bug?

A: To report this bug, you can submit a bug report to the Ansible NetBox Collection developers. This can be done by creating a new issue on the Ansible NetBox Collection GitHub repository or by sending an email to the Ansible NetBox Collection mailing list.

Q: What is the expected behavior of the netbox.netbox.netbox_device_interface module?

A: The expected behavior of the netbox.netbox.netbox_device_interface module is to accept variables for the vid and group fields in the untagged_vlan dictionary. This means that users should be able to use variables to update interfaces and untagged VLANs using the module.

Q: What are the benefits of fixing this bug?

A: The benefits of fixing this bug are:

  • It will allow users to use variables to update interfaces and untagged VLANs using the netbox.netbox.netbox_device_interface module.
  • It will improve the reliability and flexibility of automation and scripting that rely on the netbox.netbox.netbox_device_interface module.