ansible_modules icon indicating copy to clipboard operation
ansible_modules copied to clipboard

Allow netbox_ip_address module to accept raw json values as assigned objects to deal with duplicate objects

Open dsmaugy opened this issue 4 years ago • 2 comments

ISSUE TYPE
  • Feature Idea
SUMMARY

Allow netbox.netbox.netbox_ip_address module to accept raw json values for assigned_object. As of right now, any VMs or devices listed as an assigned object to an IP address has to be a string. If there are multiple devices/VMs with the same name, there is no way to differentiate between the multiple objects. An error will occur:

"msg": "More than one result returned for virtual_machine"
STEPS TO REPRODUCE

The netbox.netbox.netbox_vm_interface module is able to handle duplicate virtual machines correctly by accepting raw json values as part of the VM query. By specifying other relevant info such as VM cluster in the json, the API is able to find the correct VM even if there are multiple VMs with the same name. e.g:

netbox.netbox.netbox_vm_interface:
    ...
    data:
      # explicitly specify the cluster in case there are multiple VMs with same name
      virtual_machine: {"name": "<vm_name>", "cluster": "<cluster_name>"} 

It would be great if netbox.netbox.netbox_ip_address (and any other relevant modules) had this same functionality as netbox.netbox.netbox_vm_interface.

dsmaugy avatar Apr 09 '21 20:04 dsmaugy

Does this solve your issue? passing in dictionaries.

The only caveat to this is that the accepted key/value pairs for dictionaries must follow the fields in ALLOWED_QUERY_PARAMS constant. I've been thinking of incorporating logic into sub dictionaries to allow users to specify their own query_params such as you can do at the top level of each module using query_params

FragmentedPacket avatar May 09 '21 18:05 FragmentedPacket

Hey @FragmentedPacket ,

That doesn't work for netbox.netbox.netbox_ip_address :( The data.assigned_object.virtual_machine parameter is parsed as a string in this module and converts my dictionary into a string.

On the other hand, I've been able to successfully pass in dictionaries with the netbox.netbox.netbox_vm_interface module as the virtual_machine parameter accepts raw input and does not force a string type.

See ip_address vs vm_interface

image image

dsmaugy avatar Jul 19 '21 20:07 dsmaugy