133
133
version_added: "0.2.1"
134
134
group_by:
135
135
description:
136
- - Keys used to create groups. The I(plurals) option controls which of these are valid.
136
+ - Keys used to create groups. The I(plurals) and I(racks) options control which of these are valid.
137
137
- I(rack_group) is supported on NetBox versions 2.10 or lower only
138
138
- I(location) is supported on NetBox versions 2.11 or higher only
139
139
type: list
214
214
description: List of custom ansible host vars to create from the device object fetched from NetBox
215
215
default: {}
216
216
type: dict
217
+ racks:
218
+ description:
219
+ - If False, skip querying the racks for information, which can be slow with great amounts of racks.
220
+ - The choices of I(group_by) will be changed by this option.
221
+ type: boolean
222
+ default: True
217
223
"""
218
224
219
225
EXAMPLES = """
@@ -466,29 +472,35 @@ def group_extractors(self):
466
472
"is_virtual" : self .extract_is_virtual ,
467
473
self ._pluralize_group_by ("site" ): self .extract_site ,
468
474
self ._pluralize_group_by ("tenant" ): self .extract_tenant ,
469
- self ._pluralize_group_by ("rack" ): self .extract_rack ,
470
- "rack_role" : self .extract_rack_role ,
471
475
self ._pluralize_group_by ("tag" ): self .extract_tags ,
472
476
self ._pluralize_group_by ("role" ): self .extract_device_role ,
473
477
self ._pluralize_group_by ("platform" ): self .extract_platform ,
474
478
self ._pluralize_group_by ("device_type" ): self .extract_device_type ,
475
479
self ._pluralize_group_by ("manufacturer" ): self .extract_manufacturer ,
476
480
}
477
481
478
- # Locations were added in 2.11 replacing rack-groups.
479
- if self .api_version >= version .parse ("2.11" ):
482
+ if self .racks :
480
483
extractors .update (
481
484
{
482
- "location" : self .extract_location ,
483
- }
484
- )
485
- else :
486
- extractors .update (
487
- {
488
- "rack_group" : self .extract_rack_group ,
485
+ self ._pluralize_group_by ("rack" ): self .extract_rack ,
486
+ "rack_role" : self .extract_rack_role ,
489
487
}
490
488
)
491
489
490
+ # Locations were added in 2.11 replacing rack-groups.
491
+ if self .api_version >= version .parse ("2.11" ):
492
+ extractors .update (
493
+ {
494
+ "location" : self .extract_location ,
495
+ }
496
+ )
497
+ else :
498
+ extractors .update (
499
+ {
500
+ "rack_group" : self .extract_rack_group ,
501
+ }
502
+ )
503
+
492
504
if self .services :
493
505
extractors .update (
494
506
{
@@ -1226,8 +1238,6 @@ def lookup_processes(self):
1226
1238
self .refresh_regions_lookup ,
1227
1239
self .refresh_locations_lookup ,
1228
1240
self .refresh_tenants_lookup ,
1229
- self .refresh_racks_lookup ,
1230
- self .refresh_rack_groups_lookup ,
1231
1241
self .refresh_device_roles_lookup ,
1232
1242
self .refresh_platforms_lookup ,
1233
1243
self .refresh_device_types_lookup ,
@@ -1244,6 +1254,14 @@ def lookup_processes(self):
1244
1254
if self .services :
1245
1255
lookups .append (self .refresh_services )
1246
1256
1257
+ if self .racks :
1258
+ lookups .extend (
1259
+ [
1260
+ self .refresh_racks_lookup ,
1261
+ self .refresh_rack_groups_lookup ,
1262
+ ]
1263
+ )
1264
+
1247
1265
return lookups
1248
1266
1249
1267
@property
@@ -1494,7 +1512,11 @@ def add_host_to_groups(self, host, hostname):
1494
1512
1495
1513
if grouping not in self .group_extractors :
1496
1514
raise AnsibleError (
1497
- 'group_by option "%s" is not valid. Check group_by documentation or check the plurals option. It can determine what group_by options are valid.'
1515
+ (
1516
+ 'group_by option "%s" is not valid.'
1517
+ " Check group_by documentation or check the plurals option, as well as the racks options."
1518
+ " It can determine what group_by options are valid."
1519
+ )
1498
1520
% grouping
1499
1521
)
1500
1522
@@ -1782,5 +1804,6 @@ def parse(self, inventory, loader, path, cache=True):
1782
1804
self .virtual_chassis_name = self .get_option ("virtual_chassis_name" )
1783
1805
self .dns_name = self .get_option ("dns_name" )
1784
1806
self .ansible_host_dns_name = self .get_option ("ansible_host_dns_name" )
1807
+ self .racks = self .get_option ("racks" )
1785
1808
1786
1809
self .main ()
0 commit comments