Skip to content

Commit cf668c7

Browse files
Enhancement: nb_inventory - group_by for services (#310)
1 parent 59e2535 commit cf668c7

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
- cluster_type
128128
- cluster_group
129129
- is_virtual
130+
- services
130131
default: []
131132
group_names_raw:
132133
description: Will not add the group_by choice name to the group names
@@ -1066,6 +1067,11 @@ def generate_group_name(self, grouping, group):
10661067
# Don't create the inverse group
10671068
return None
10681069

1070+
# Special case. Extract name from service, which is a hash.
1071+
if grouping == "services":
1072+
group = group["name"]
1073+
grouping = "service"
1074+
10691075
if self.group_names_raw:
10701076
return group
10711077
else:

tests/integration/targets/inventory/files/test-inventory.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@
736736
"region_other_region",
737737
"region_parent_region",
738738
"role_core_switch",
739+
"service_http",
740+
"service_ssh",
741+
"service_telnet",
739742
"site_test_site2",
740743
"ungrouped"
741744
]
@@ -825,6 +828,22 @@
825828
"test100"
826829
]
827830
},
831+
"service_ssh": {
832+
"hosts": [
833+
"Test VM With Spaces",
834+
"test100"
835+
]
836+
},
837+
"service_http": {
838+
"hosts": [
839+
"test100"
840+
]
841+
},
842+
"service_telnet": {
843+
"hosts": [
844+
"Test Nexus One"
845+
]
846+
},
828847
"site_test_site": {
829848
"hosts": [
830849
"Test Nexus One",

tests/integration/targets/inventory/files/test-inventory.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ group_by:
2222
- cluster_group
2323
- cluster_type
2424
- is_virtual
25+
- services

0 commit comments

Comments
 (0)