diff options
author | Simon Metzger <simon.metzger@dm.de> | 2016-10-11 13:47:05 +0200 |
---|---|---|
committer | Simon Metzger <simon.metzger@dm.de> | 2016-10-14 20:20:28 +0200 |
commit | 23573e02a89060c4882d810fc2f18555c665519f (patch) | |
tree | 8f0c99be059e10d70e4f3748edde770a28e8480c | |
parent | faa364138450fc390906956e2db358387200e19d (diff) |
Newer foreman versions (1.13.0 and later) should use hostgroup_title
instead of hostgroup_name to correctly return nested hostgroups to ansible
-rwxr-xr-x | foreman_ansible_inventory.py | 11 |
1 files 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())) |