mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #7184/0c03f34f backport][stable-7] plugins/inventory/cobbler: Add exclude/include_mgmt_classes (#7208)
plugins/inventory/cobbler: Add exclude/include_mgmt_classes (#7184)
(cherry picked from commit 0c03f34f54
)
Co-authored-by: Orion Poplawski <orion@nwra.com>
This commit is contained in:
parent
0f300bddb9
commit
aa2a5d9578
2 changed files with 26 additions and 3 deletions
2
changelogs/fragments/7184-cobbler-mgmt-classes.yml
Normal file
2
changelogs/fragments/7184-cobbler-mgmt-classes.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- cobbler inventory plugin - add ``exclude_mgmt_classes`` and ``include_mgmt_classes`` options to exclude or include hosts based on management classes (https://github.com/ansible-collections/community.general/pull/7184).
|
|
@ -42,6 +42,12 @@ DOCUMENTATION = '''
|
||||||
description: Fallback to cached results if connection to cobbler fails.
|
description: Fallback to cached results if connection to cobbler fails.
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
exclude_mgmt_classes:
|
||||||
|
description: Management classes to exclude from inventory.
|
||||||
|
type: list
|
||||||
|
default: []
|
||||||
|
elements: str
|
||||||
|
version_added: 7.4.0
|
||||||
exclude_profiles:
|
exclude_profiles:
|
||||||
description:
|
description:
|
||||||
- Profiles to exclude from inventory.
|
- Profiles to exclude from inventory.
|
||||||
|
@ -49,6 +55,12 @@ DOCUMENTATION = '''
|
||||||
type: list
|
type: list
|
||||||
default: []
|
default: []
|
||||||
elements: str
|
elements: str
|
||||||
|
include_mgmt_classes:
|
||||||
|
description: Management classes to include from inventory.
|
||||||
|
type: list
|
||||||
|
default: []
|
||||||
|
elements: str
|
||||||
|
version_added: 7.4.0
|
||||||
include_profiles:
|
include_profiles:
|
||||||
description:
|
description:
|
||||||
- Profiles to include from inventory.
|
- Profiles to include from inventory.
|
||||||
|
@ -216,6 +228,8 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
||||||
self.cache_key = self.get_cache_key(path)
|
self.cache_key = self.get_cache_key(path)
|
||||||
self.use_cache = cache and self.get_option('cache')
|
self.use_cache = cache and self.get_option('cache')
|
||||||
|
|
||||||
|
self.exclude_mgmt_classes = self.get_option('exclude_mgmt_classes')
|
||||||
|
self.include_mgmt_classes = self.get_option('include_mgmt_classes')
|
||||||
self.exclude_profiles = self.get_option('exclude_profiles')
|
self.exclude_profiles = self.get_option('exclude_profiles')
|
||||||
self.include_profiles = self.get_option('include_profiles')
|
self.include_profiles = self.get_option('include_profiles')
|
||||||
self.group_by = self.get_option('group_by')
|
self.group_by = self.get_option('group_by')
|
||||||
|
@ -265,10 +279,17 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
||||||
hostname = host['hostname'] # None
|
hostname = host['hostname'] # None
|
||||||
interfaces = host['interfaces']
|
interfaces = host['interfaces']
|
||||||
|
|
||||||
|
if set(host['mgmt_classes']) & set(self.include_mgmt_classes):
|
||||||
|
self.display.vvvv('Including host %s in mgmt_classes %s\n' % (host['name'], host['mgmt_classes']))
|
||||||
|
else:
|
||||||
if self._exclude_profile(host['profile']):
|
if self._exclude_profile(host['profile']):
|
||||||
self.display.vvvv('Excluding host %s in profile %s\n' % (host['name'], host['profile']))
|
self.display.vvvv('Excluding host %s in profile %s\n' % (host['name'], host['profile']))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if set(host['mgmt_classes']) & set(self.exclude_mgmt_classes):
|
||||||
|
self.display.vvvv('Excluding host %s in mgmt_classes %s\n' % (host['name'], host['mgmt_classes']))
|
||||||
|
continue
|
||||||
|
|
||||||
# hostname is often empty for non-static IP hosts
|
# hostname is often empty for non-static IP hosts
|
||||||
if hostname == '':
|
if hostname == '':
|
||||||
for iname, ivalue in interfaces.items():
|
for iname, ivalue in interfaces.items():
|
||||||
|
|
Loading…
Reference in a new issue