Skip to content

Commit

Permalink
Cope with Ansible >= 2.4 inventory changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Nils Philippsen <nils@redhat.com>
  • Loading branch information
nphilipp committed Jun 9, 2020
1 parent 60198dc commit 6bbe8b7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/ansiblereview/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit 6bbe8b7

Please sign in to comment.