From 267502c2b33174655047c272d805aee91bbcdd6d Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Thu, 5 Dec 2019 10:32:31 +0100 Subject: [PATCH] Cope with Ansible >= 2.4 inventory changes. Signed-off-by: Nils Philippsen --- lib/ansiblereview/inventory.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/ansiblereview/inventory.py b/lib/ansiblereview/inventory.py index 2c6fc52..05dfe53 100644 --- a/lib/ansiblereview/inventory.py +++ b/lib/ansiblereview/inventory.py @@ -13,6 +13,10 @@ from ansible.vars.manager import VariableManager except ImportError: from ansible.vars import VariableManager + if not hasattr(ansible.inventory, 'Inventory'): + # The inventory system was reworked in Ansible 2.4. + import ansible.inventory.manager + ANSIBLE = 2.4 def no_vars_in_host_file(candidate, options): @@ -32,9 +36,17 @@ def parse(candidate, options): try: if ANSIBLE > 1: loader = ansible.parsing.dataloader.DataLoader() - var_manager = VariableManager() - ansible.inventory.Inventory(loader=loader, variable_manager=var_manager, - host_list=candidate.path) + if ANSIBLE > 2: + inventory = ansible.inventory.manager.InventoryManager( + sources=candidate.path, + loader=loader, + ) + VariableManager(loader=loader, inventory=inventory) + else: + var_manager = VariableManager() + ansible.inventory.Inventory(loader=loader, + variable_manager=var_manager, + host_list=candidate.path) else: ansible.inventory.Inventory(candidate.path) except Exception as e: