aboutsummaryrefslogtreecommitdiff
path: root/foreman_ansible_inventory.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-02-13 18:27:20 +0100
committerGuido Günther <agx@sigxcpu.org>2016-02-13 18:27:20 +0100
commit7f0a637052bba67dad630886fd0f2f4446d07f4c (patch)
treea4409970384244e75af876d35191c827a0f0f701 /foreman_ansible_inventory.py
parentb61d34ea2f30c1d92f366fc94f9a04d032248707 (diff)
Group by location and organization as well
Diffstat (limited to 'foreman_ansible_inventory.py')
-rwxr-xr-xforeman_ansible_inventory.py10
1 files changed, 6 insertions, 4 deletions
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