1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

plugins/inventory/cobbler: Add option to use system name for inventory (#6502)

* plugins/inventory/cobbler: Add option to use system name for inventory hostname (#6492)

* plugins/inventory/cobbler: Add warning for systems with empty profiles
This commit is contained in:
Orion Poplawski 2023-05-29 10:53:56 -06:00 committed by GitHub
parent 4373f2f33b
commit 8586adcd51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View file

@ -0,0 +1,3 @@
minor_changes:
- cobbler inventory plugin - add ``inventory_hostname`` option to allow using the system name for the inventory hostname (https://github.com/ansible-collections/community.general/pull/6502).
- cobbler inventory plugin - add warning for systems with empty profiles (https://github.com/ansible-collections/community.general/pull/6502).

View file

@ -56,6 +56,15 @@ DOCUMENTATION = '''
default: [] default: []
elements: str elements: str
version_added: 4.4.0 version_added: 4.4.0
inventory_hostname:
description:
- What to use for the ansible inventory hostname.
- By default the networking hostname is used if defined, otherwise the DNS name of the management or first non-static interface.
- If set to I(system), the cobbler system name is used.
type: str
choices: [ 'hostname', 'system' ]
default: hostname
version_added: 7.1.0
group_by: group_by:
description: Keys to group hosts by description: Keys to group hosts by
type: list type: list
@ -201,6 +210,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
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')
self.inventory_hostname = self.get_option('inventory_hostname')
for profile in self._get_profiles(): for profile in self._get_profiles():
if profile['parent']: if profile['parent']:
@ -238,6 +248,9 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
for host in self._get_systems(): for host in self._get_systems():
# Get the FQDN for the host and add it to the right groups # Get the FQDN for the host and add it to the right groups
if self.inventory_hostname == 'system':
hostname = host['name'] # None
else:
hostname = host['hostname'] # None hostname = host['hostname'] # None
interfaces = host['interfaces'] interfaces = host['interfaces']
@ -262,8 +275,11 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
self.display.vvvv('Added host %s hostname %s\n' % (host['name'], hostname)) self.display.vvvv('Added host %s hostname %s\n' % (host['name'], hostname))
# Add host to profile group # Add host to profile group
if host['profile'] != '':
group_name = self._add_safe_group_name(host['profile'], child=hostname) group_name = self._add_safe_group_name(host['profile'], child=hostname)
self.display.vvvv('Added host %s to profile group %s\n' % (hostname, group_name)) self.display.vvvv('Added host %s to profile group %s\n' % (hostname, group_name))
else:
self.display.warning('Host %s has an empty profile\n' % (hostname))
# Add host to groups specified by group_by fields # Add host to groups specified by group_by fields
for group_by in self.group_by: for group_by in self.group_by: