Skip to content
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

netbox_device_interface error using 'mode'. #158

Closed
ThomasADavis opened this issue Apr 4, 2020 · 9 comments · Fixed by #162
Closed

netbox_device_interface error using 'mode'. #158

ThomasADavis opened this issue Apr 4, 2020 · 9 comments · Fixed by #162
Labels
bug Something isn't working PR Submitted

Comments

@ThomasADavis
Copy link
Contributor

ISSUE TYPE
  • Bug Report
SOFTWARE VERSIONS
Ansible:

[tdavis@mouse-r11 netbox]$ ansible --version
ansible 2.9.6
config file = /home/tdavis/netbox/ansible.cfg
configured module search path = ['/home/tdavis/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/tdavis/.local/lib/python3.6/site-packages/ansible
executable location = /home/tdavis/.local/bin/ansible
python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]

Netbox:

v2.7.11

Collection:

github head installed.

SUMMARY

Tagged All vs. Tagged (All)

STEPS TO REPRODUCE
    - name: create real interfaces
      netbox_device_interface:
        netbox_url: "{{ endpoint }}"
        netbox_token: "{{ token }}"
        data:
          device: "{{ ansible_hostname }}"
          name: "{{ item.name }}"
          form_factor: "{{ item.form_factor }}"
          tags: "{{ item.tags }}"
          mode: "Tagged All"
          mtu: "{{ item.mtu | default(1514) }}"
      loop: "{{ interfaces }}"

EXPECTED RESULTS

succeded.

ACTUAL RESULTS
failed: [mouse-r12] (item={'name': 'enp2s0', 'form_factor': '1000BASE-T (1GE)', 'tags': ['ovsbridge:br-external'], 'mtu': 9216}) => {"ansible_loop_var": "item", "changed": false, "item": {"form_factor": "1000BASE-T (1GE)", "mtu": 9216, "name": "enp2s0", "tags": ["ovsbridge:br-external"]}, "msg": "Tagged All was not found as a valid choice for interfaces"}

Looking at the _choices API, it should be 'Tagged (All)', not 'Tagged All'. This affects netbox_vm_interface, netbox_device_interface, and netbox_interface.

@FragmentedPacket
Copy link
Contributor

@ThomasADavis I'm sorry, but what is the exact issue here? The choices are fetched dynamically for the two modules that we're support (netbox_device_interface and netbox_vm_interface) from the NetBox API so the user will have to pass in the correct mode that would be valid for NetBox.

Is this a documentation issue? Sorry just not very clear as to where the issue is.

@ThomasADavis
Copy link
Contributor Author

They are not dynamic.

def main():
    """
    Main entry point for module execution
    """
    argument_spec = NETBOX_ARG_SPEC
    argument_spec.update(
        dict(
            update_vc_child=dict(type="bool", required=False, default=False),
            data=dict(
                type="dict",
                required=True,
                options=dict(
                    device=dict(required=False, type="raw"),
                    name=dict(required=True, type="str"),
                    form_factor=dict(required=False, type="raw"),
                    enabled=dict(required=False, type="bool"),
                    lag=dict(required=False, type="raw"),
                    mtu=dict(required=False, type="int"),
                    mac_address=dict(required=False, type="str"),
                    mgmt_only=dict(required=False, type="bool"),
                    description=dict(required=False, type="str"),
                    mode=dict(
                        required=False, choices=["Access", "Tagged", "Tagged All"],
                    ),
                    untagged_vlan=dict(required=False, type="raw"),
                    tagged_vlans=dict(required=False, type="raw"),
                    tags=dict(required=False, type="list"),
                ),
            ),
        )
    )

Hard coded values in the modules.

When using netbox 2.7, that should be 'Tagged (All)', not 'Tagged All'

All three modules have the same hard coded values.

@FragmentedPacket
Copy link
Contributor

Great. Thank you for the specifics. I can get something put in tonight hopefully.

@ThomasADavis
Copy link
Contributor Author

Looks like it should just be commented out, not changed - netbox-2.8 is the flag day version for slugs.

@FragmentedPacket
Copy link
Contributor

Did you mean to close this issue? And we can make a decision as to whether it should be commented out or not.

I'd rather have a few choices (slug and not slug) that it will validate whether they provided the correct options, but having the API report back that it is an invalid option is also fine and prevents having the argument spec, but goes through all the logic, etc. before failing.

@ThomasADavis
Copy link
Contributor Author

Dang it. Hit the wrongbutton.

@ThomasADavis ThomasADavis reopened this Apr 5, 2020
@ThomasADavis
Copy link
Contributor Author

I looked in other modules, the same code section was commented out, and appears to handled somewhere else.

and it only affects netbox_vm_interface and netbox_device_interface. netbox_interfaces does no checking.

@FragmentedPacket
Copy link
Contributor

Yeah the argument spec is newer. I think changing the type to raw and then I'll look at the back end code since I think those are available from the _choices API endpoint

@ThomasADavis
Copy link
Contributor Author

Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR Submitted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants