Skip to content

Commit 609a854

Browse files
Enhancement - Inventory: make it optional to query for services (#143) (#154)
1 parent 1e74051 commit 609a854

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
default: False
5555
type: boolean
5656
version_added: "0.1.7"
57+
services:
58+
description:
59+
- If True, it adds the device or virtual machine services information in host vars.
60+
default: True
61+
type: boolean
62+
version_added: "2.0"
5763
group_by:
5864
description: Keys used to create groups.
5965
type: list
@@ -308,9 +314,14 @@ def extract_platform(self, host):
308314

309315
def extract_services(self, host):
310316
try:
311-
url = self.api_endpoint + "/api/ipam/services/?device=" + str(host["name"])
312-
device_lookup = self._fetch_information(url)
313-
return device_lookup["results"]
317+
if self.services:
318+
url = (
319+
self.api_endpoint
320+
+ "/api/ipam/services/?device="
321+
+ str(host["name"])
322+
)
323+
device_lookup = self._fetch_information(url)
324+
return device_lookup["results"]
314325
except Exception:
315326
return
316327

@@ -668,6 +679,7 @@ def parse(self, inventory, loader, path, cache=True):
668679
self.validate_certs = self.get_option("validate_certs")
669680
self.config_context = self.get_option("config_context")
670681
self.interfaces = self.get_option("interfaces")
682+
self.services = self.get_option("services")
671683
self.headers = {
672684
"Authorization": "Token %s" % token,
673685
"User-Agent": "ansible %s Python %s"

0 commit comments

Comments
 (0)