From 23573e02a89060c4882d810fc2f18555c665519f Mon Sep 17 00:00:00 2001 From: Simon Metzger Date: Tue, 11 Oct 2016 13:47:05 +0200 Subject: Newer foreman versions (1.13.0 and later) should use hostgroup_title instead of hostgroup_name to correctly return nested hostgroups to ansible --- foreman_ansible_inventory.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py index d969360..d74a521 100755 --- a/foreman_ansible_inventory.py +++ b/foreman_ansible_inventory.py @@ -256,8 +256,15 @@ class ForemanInventory(object): 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 + group = 'hostgroup' + val = host.get('%s_title' % group) or host.get('%s_name' % group) + if val: + safe_key = self.to_safe('%s%s_%s' % (self.group_prefix, group, 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())) -- cgit v1.2.3