Navigation Menu

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

Add devices to virtual chassis error -> "More than one result returned for virtual_chassis" #402

Closed
jefvantongerloo opened this issue Dec 28, 2020 · 13 comments · Fixed by #405
Labels
bug Something isn't working PR Submitted

Comments

@jefvantongerloo
Copy link

Environment

  • Docker NetBox-Docker version: 0.27.0
  • Ansible Netbox.netbox collection: 1.2.0
  • Python PyNetbox: 5.1.2
  • Python Ansible-base: 2.10.4
  • NetBox version: 2.9.9 (worked) & 2.10.2 (bugged)

Adding devices to a virtual chassis through the Ansible netbox.netbox collection gives an error on the second device/chassis added to the same virtual chassis: "More than one result returned for virtual_chassis". Error first seen in version 2.10.2, Downgraded to version 2.9.9 and confirmed to be working.

Sample inventory:

    SWITCH-001:
      ansible_host: 10.10.10.1
      device_role: Access Switch
      device_chassis:
        - type: OS6560-P48X4
          unit: 1
        - type: OS6560-P48X4
          unit: 2
        - type: OS6560-P48X4
          unit: 3

Playbook:

   - name: Create virtual chassis
      netbox_virtual_chassis:
        netbox_url: '{{ netbox_url }}'
        netbox_token: '{{ netbox_token }}'
        data:
          name: '{{ inventory_hostname }}'
          master: '{{ inventory_hostname + "-1" }}'
        state: present
    - name: Add devices to Virtual chassis
      netbox_device:
        netbox_url: '{{ netbox_url }}'
        netbox_token: '{{ netbox_token }}'
        data:
          name: '{{ inventory_hostname + "-" + item.unit|string }}'
          virtual_chassis: '{{ inventory_hostname }}'
          vc_position: '{{ item.unit}}'
      loop: '{{ device_chassis  }}'

Steps to Reproduce

  • Ansible: add device through netbox.netbox.netbox_device module
  • Ansible: create virtual chassis through netbox.netbox.netbox_virtual_chassis module
  • Ansible: update devices to add them to virtual chassis through netbox.netbox.netbox_device module

What did you expect to happen?
One virtual chassis with three added chassis/devices linked

What happened instead?
Netbox version 2.9.9: worked fine
Netbox version 2.10.2: Ansible error and only two chassis/devices added to virtual chassis.

@FragmentedPacket
Copy link
Contributor

Thanks for the report!

Could you please test the PR and let me know if that resolved your issue?

@FragmentedPacket FragmentedPacket added bug Something isn't working PR Submitted labels Dec 31, 2020
@jefvantongerloo
Copy link
Author

No, now all requests for adding devices to the virtual chassis fail.

@FragmentedPacket
Copy link
Contributor

What's the failure message?

@jefvantongerloo
Copy link
Author

jefvantongerloo commented Jan 4, 2021

This is the -vvv output for trying to add unit 2 to the VC:

The full traceback is:
  File "/tmp/ansible_netbox_device_payload_bjati7rz/ansible_netbox_device_payload.zip/ansible_collections/netbox/netbox/plugins/module_utils/netbox_utils.py", line 519, in _nb_endpoint_get
    response = nb_endpoint.get(**query_params)
  File "/home/xxx/.local/lib/python3.8/site-packages/pynetbox/core/endpoint.py", line 141, in get
    raise ValueError(
failed: [SWITCH-001] (item={'type': 'OS6560-P48X4', 'unit': 2}) => changed=false 
  ansible_loop_var: chassis
  chassis:
    type: OS6560-P48X4
    unit: 2
  invocation:
    module_args:
      data:
        asset_tag: null
        cluster: null
        comments: null
        custom_fields: null
        device_role: null
        device_type: null
        face: null
        local_context_data: null
        name: SWITCH-001-2
        platform: null
        position: null
        primary_ip4: null
        primary_ip6: null
        rack: null
        serial: null
        site: null
        status: null
        tags: null
        tenant: null
        vc_position: 2
        vc_priority: null
        virtual_chassis: SWITCH-001
      netbox_token: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      netbox_url: http://localhost:8000
      query_params: null
      state: present
      validate_certs: true
  msg: More than one result returned for virtual_chassis

@FragmentedPacket
Copy link
Contributor

I'm not really able to replicate this exactly as you say.

I get the same results whether on 2.9 or 2.10 and the latest collection, which is partly what you're seeing with it not being able to resolve it since there isn't a unique search option for it.. Do you have more definitive example that I can use to test?

I do see the issue with it returning more than result and I've opened an issue with NetBoxhttps://github.com/netbox-community/netbox/issues/5586 to resolve part of the source of this issue. Once it's accepted, I can work on the code and get it submitted and then a release would be made at some point.

@FragmentedPacket
Copy link
Contributor

The PR has been submitted.

If you use the PR above and change your definition to:

 virtual_chassis:
  name: "{{ inventory_hostname }}"
  master: "{{ inventory_hostname + '-1' }}"

Does that resolve your issue?

@jefvantongerloo
Copy link
Author

jefvantongerloo commented Jan 13, 2021

It does not resolve the issue, still the same error:

The full traceback is:
  File "/tmp/ansible_netbox_device_payload_p8__ijie/ansible_netbox_device_payload.zip/ansible_collections/netbox/netbox/plugins/module_utils/netbox_utils.py", line 518, in _nb_endpoint_get
    response = nb_endpoint.get(**query_params)
  File "/home/xxx/.local/lib/python3.8/site-packages/pynetbox/core/endpoint.py", line 141, in get
    raise ValueError(
failed: [SWITCH-001] (item={'type': 'OS6860E-P24', 'unit': 1}) => changed=false 
  ansible_loop_var: chassis
  chassis:
    type: OS6860E-P24
    unit: 1
  invocation:
    module_args:
      data:
        asset_tag: null
        cluster: null
        comments: null
        custom_fields: null
        device_role: null
        device_type: null
        face: null
        local_context_data: null
        name: SWITCH-001-1
        platform: null
        position: null
        primary_ip4: null
        primary_ip6: null
        rack: null
        serial: null
        site: null
        status: null
        tags: null
        tenant: null
        vc_position: 1
        vc_priority: null
        virtual_chassis:
          master: SWITCH-001-1
          name: SWITCH-001
      netbox_token: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      netbox_url: http://localhost:8000
      query_params: null
      state: present
      validate_certs: true
  msg: More than one result returned for virtual_chassis

Installed Netbox.netbox collection 1.2.1:

Collection           Version
-------------------- -------
ansible.netcommon    1.4.1  
netbox.netbox        1.2.1 

Changed playbook to vc with name and master parameters:

- name: NetBox - Add devices to Virtual chassis
      netbox_device:
        netbox_url: '{{ netbox_url }}'
        netbox_token: '{{ netbox_token }}'
        data:
          name: '{{ inventory_hostname + "-" + chassis.unit|string }}'
          virtual_chassis:
            name: "{{ inventory_hostname }}"
            master: "{{ inventory_hostname + '-1' }}"
          vc_position: '{{ chassis.unit|string}}'
        state: present
      loop: '{{ device_chassis  }}'
      loop_control:
        loop_var: chassis

@jefvantongerloo
Copy link
Author

jefvantongerloo commented Feb 18, 2021

PR has been added into the Netbox release v2.10.4, but still the same issue.

Tested with:

  • Netbox 2.10.4
  • Netbox.netbox 1.2.1
failed: [SWITCH-001] (item={'type': 'OS6560-P48X4', 'unit': 4}) => changed=false 
  ansible_loop_var: chassis
  chassis:
    type: OS6560-P48X4
    unit: 4
  msg: More than one result returned for virtual_chassis

Example task for adding chassis to VC with:
SWI-001 = Virtual Chassis (existing)
SWI-001-1 = Chassis (VC master, already added)
SWI-001-2 = Chassis VC unit 2 to be added

    - name: NetBox - Add devices to Virtual chassis
      netbox_device:
        netbox_url: '{{ netbox_url }}'
        netbox_token: '{{ netbox_token }}'
        data:
          name: SWI-001-2
          virtual_chassis:
            master: SWI-001-1
            name: SWI-001
          vc_position: 2
        state: present

@FragmentedPacket
Copy link
Contributor

I haven't merged in the code yet. Sorry life has been really busy, but I do need to get this resolved for you.

@jefvantongerloo
Copy link
Author

No problem, just keeping track of changes :)
Looking forward to the implementation, but I understand life can be busy.

@igloo777
Copy link

igloo777 commented Mar 6, 2021

Thanks for the report!

Could you please test the PR and let me know if that resolved your issue?

I tested in my environment, and it works for me.

@jefvantongerloo
Copy link
Author

Thanks for the report!
Could you please test the PR and let me know if that resolved your issue?

I tested in my environment, and it works for me.

Have you tested the issue #465 or also adding devices to VC's?
Could you share a sample inventory and playbook?

@andresgsc
Copy link

Hi, I'm facing this issue when I try to create a virtual chassis from ansible. It is a simple ansible task with just the name of the virtual chassis. I get the following:

fatal: [SW-1]: FAILED! => {"changed": false, "msg": "More than one result returned for SW-1"}

My environment is:
ansible 2.10.7
python 3.6.8
netbox v2.11.2
netbox.netbox 3.0.0

Anyone else facing this? Thanks !!

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.

4 participants