From b6d41691bb667bb3c1063c6636144b3d3de547a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Mon, 25 Jul 2022 10:09:09 +0200 Subject: [PATCH] Host collections group names are customizable on the Foreman inventory plugin --- plugins/inventory/foreman.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/inventory/foreman.py b/plugins/inventory/foreman.py index a123217f7d..b14566425e 100644 --- a/plugins/inventory/foreman.py +++ b/plugins/inventory/foreman.py @@ -56,6 +56,9 @@ group_prefix: description: prefix to apply to foreman groups default: foreman_ + hostcollection_group_prefix: + description: prefix to apply to foreman groups generated from host collections + default: foreman_hostcollection_ vars_prefix: description: prefix to apply to host variables, does not include facts nor params default: foreman_ @@ -460,6 +463,7 @@ def _populate_report_api(self): self._populate_host_api() return self.group_prefix = self.get_option('group_prefix') + self.hostcollection_group_prefix = self.get_option('hostcollection_group_prefix') hostnames = self.get_option('hostnames') strict = self.get_option('strict') @@ -547,8 +551,8 @@ def _populate_report_api(self): # Create Ansible groups for host collections for hostcollection in hostcollections: try: - host_collection_group_name = to_safe_group_name('%shostcollection_%s' % ( - to_text(self.group_prefix), + host_collection_group_name = to_safe_group_name('%s%s' % ( + to_text(self.hostcollection_group_prefix), to_text(hostcollection).lower() )) hostcollection_group = self.inventory.add_group(host_collection_group_name) @@ -643,7 +647,7 @@ def _populate_host_api(self): # Create Ansible groups for host collections for hostcollection in hostcollections: try: - hostcollection_group = to_safe_group_name('%shostcollection_%s' % (self.get_option('group_prefix'), + hostcollection_group = to_safe_group_name('%s%s' % (self.get_option('hostcollection_group_prefix'), hostcollection['name'].lower().replace(" ", ""))) hostcollection_group = self.inventory.add_group(hostcollection_group) self.inventory.add_child(hostcollection_group, host_name)