Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Prefer hostgroup title over hostgroup name #54

Open
wants to merge 1 commit into
base: master
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: 8 additions & 2 deletions foreman_ansible_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,14 @@ def update_cache(self):
for host in self._get_hosts():
dns_name = host['name']

# Create ansible groups for hostgroup, environment, location and organization
for group in ['hostgroup', 'environment', 'location', 'organization']:
# Create ansible groups for hostgroup
val = host.get('hostgroup_title') or host.get('hostgroup_name')
if val:
safe_key = self.to_safe('%s%s_%s' % (self.group_prefix, 'hostgroup', val.lower()))
self.push(self.inventory, safe_key, dns_name)

# Create ansible groups for environment, location and organization
for group in ['environment', 'location', 'organization']:
val = host.get('%s_name' % group)
if val:
safe_key = self.to_safe('%s%s_%s' % (self.group_prefix, group, val.lower()))
Expand Down