From c876f4f3cf891eea54c620e974ba6bcaf9047540 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Sat, 19 Aug 2017 01:16:43 +0530 Subject: [PATCH] Make FreeIPA inventory work (#25354) Signed-off-by: Abhijeet Kasurde --- contrib/inventory/freeipa.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/inventory/freeipa.py b/contrib/inventory/freeipa.py index c07fe335bab..30ca9794ea3 100755 --- a/contrib/inventory/freeipa.py +++ b/contrib/inventory/freeipa.py @@ -3,6 +3,7 @@ import argparse from ipalib import api import json +from distutils.version import StrictVersion def initialize(): @@ -31,13 +32,17 @@ def list_groups(api): inventory = {} hostvars = {} - meta = {} + ipa_version = api.Command.env()['result']['version'] result = api.Command.hostgroup_find()['result'] for hostgroup in result: # Get direct and indirect members (nested hostgroups) of hostgroup members = [] + if StrictVersion(ipa_version) >= StrictVersion('4.0.0'): + hostgroup_name = hostgroup['cn'][0] + hostgroup = api.Command.hostgroup_show(hostgroup_name)['result'] + if 'member_host' in hostgroup: members = [host for host in hostgroup['member_host']] if 'memberindirect_host' in hostgroup: