Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable hostcollection group names with the Foreman inventory #1445

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions plugins/inventory/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down