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:
parent
4373f2f33b
commit
8586adcd51
2 changed files with 22 additions and 3 deletions
3
changelogs/fragments/6502-cobbler-inventory_hostname.yml
Normal file
3
changelogs/fragments/6502-cobbler-inventory_hostname.yml
Normal 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).
|
|
@ -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,7 +248,10 @@ 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
|
||||||
hostname = host['hostname'] # None
|
if self.inventory_hostname == 'system':
|
||||||
|
hostname = host['name'] # None
|
||||||
|
else:
|
||||||
|
hostname = host['hostname'] # None
|
||||||
interfaces = host['interfaces']
|
interfaces = host['interfaces']
|
||||||
|
|
||||||
if self._exclude_profile(host['profile']):
|
if self._exclude_profile(host['profile']):
|
||||||
|
@ -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
|
||||||
group_name = self._add_safe_group_name(host['profile'], child=hostname)
|
if host['profile'] != '':
|
||||||
self.display.vvvv('Added host %s to profile group %s\n' % (hostname, group_name))
|
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))
|
||||||
|
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:
|
||||||
|
|
Loading…
Reference in a new issue