From 7f0a637052bba67dad630886fd0f2f4446d07f4c Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sat, 13 Feb 2016 18:27:20 +0100 Subject: Group by location and organization as well --- foreman_ansible_inventory.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'foreman_ansible_inventory.py') diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py index fef584b..bb2f6d4 100755 --- a/foreman_ansible_inventory.py +++ b/foreman_ansible_inventory.py @@ -181,10 +181,12 @@ class ForemanInventory(object): for host in self._get_hosts(): dns_name = host['name'] - hostgroup = host.get('hostgroup_name') - if hostgroup: - hkey = self.to_safe('foreman_' + hostgroup.lower()) - self.push(self.inventory, hkey, dns_name) + # Create ansible groups for hostgroup, location and organization + for group in ['hostgroup', 'location', 'organization']: + val = host.get('%s_name' % group) + if val: + safe_key = self.to_safe('foreman_%s_%s' % (group, val.lower())) + self.push(self.inventory, safe_key, dns_name) # Ansible groups by parameters in host groups based # on group_patterns in config -- cgit v1.2.3