Skip to content

Conversation

@yodzeb
Copy link
Contributor

@yodzeb yodzeb commented Jun 12, 2025

Related Issue

#1426

New Behavior

netbox_service module is working again, with either device or virtual_machine parameter, corretly mapped to API parameters

Discussion: Benefits and Drawbacks

Not sure if the extra params should be cleaned in netbox_ipam.py after being moved to API parameters., but it's working.

Changes to the Documentation

None

Proposed Release Note Entry

Changelog fragment pushed

Double Check

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

@sc68cal
Copy link
Contributor

sc68cal commented Jun 12, 2025

looks good otherwise

@yodzeb yodzeb mentioned this pull request Jun 13, 2025
3 tasks
ok, thx

Co-authored-by: Sean M. Collins <sean@coreitpro.com>
@StoffelCPR
Copy link
Contributor

Can this be merged then?

@sc68cal sc68cal merged commit 6e91156 into netbox-community:devel Jun 17, 2025
50 of 53 checks passed
@cernymi
Copy link

cernymi commented Oct 15, 2025

We're trying netbox.netbox.netbox_service against Netbox 4.4.4
After fix on Netbox side #20554 (existed from 4.3.0 - 4.4.3)

And now we can test netbox_service is failing on:

  • services = 0 - if there's no service with this name in Netbox - just OK - is created

  • services = 1 - if there's exactly one service with this name in Netbox - always reassign service to last parent_object_id - KO

--- before
+++ after
@@ -1,2 +1,2 @@
-    parent_object_id: 267
+    parent_object_id: 264
  • services > 1 - if there are more services with same name already in Netbox - KO
 msg: More than one result returned for ...

Example test snippet:

- name: new netbox service - create
    netbox.netbox.netbox_service:
      netbox_url: "{{ netbox_url }}"
      netbox_token: "{{ netbox_rw_token }}"
      validate_certs: "{{ netbox_validate_certs }}"
      data:
        name: "{{ service_create.name | mandatory }}"
        protocol: "{{ service_create.protocol | lower | mandatory }}"
        description: "{{ service_create.description | default(omit) }}"
        device: "{{ service_create.device | default(omit) }}"
        ipaddresses: "{{ service_create.ipaddresses | default(omit) }}"
        port: "{{ service_create.port | default(omit) }}"
        ports: "{{ service_create.ports | default(omit) }}"
        tags: "{{ service_create.tags | default(omit) }}"
        virtual_machine: "{{ service_create.virtual_machine | default(tenant_vm.name) }}"
    vars:
      service_create:
        name: test_service_https
        protocol: tcp
        virtual_machine: <existing_vm>
        ports: [443]

This change is maybe missing parent_object_type and parent_object_id in query set?

diff --git a/plugins/module_utils/netbox_utils.py b/plugins/module_utils/netbox_utils.py
index 2d55498..e2dee16 100644
--- a/plugins/module_utils/netbox_utils.py
+++ b/plugins/module_utils/netbox_utils.py
@@ -558,7 +558,7 @@ ALLOWED_QUERY_PARAMS = {
    "rir": set(["slug"]),
    "role": set(["slug"]),
    "route_target": set(["name"]),
-    "services": set(["device", "virtual_machine", "name", "port", "protocol"]),
+    "services": set(["device", "virtual_machine", "name", "port", "protocol", "parent_object_type", "parent_object_id"]),
    "service_template": set(["name"]),
    "site": set(["slug", "name"]),
    "site_group": set(["slug"]),

Or something better?
But netbox_service seems to be working for us after this change.

Is it possible look at it and find some way how to fix it properly?
Thank you

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.

4 participants