inventory_reader.py 596 Bytes
#!/usr/bin/python
# -*- coding: UTF-8 -*-

"""
   read host info from inventory files

"""

from ansible.parsing.dataloader import DataLoader
from ansible.inventory.manager import InventoryManager
import os


class InventoryReader:

    @staticmethod
    def get_inventory_ifo(az, group):
        """
        get hosts info from ansible inventory file
        """
        data_loader = DataLoader()
        inventory = InventoryManager(loader=data_loader,
                                     sources=[os.path.join("./inventories", az, 'hosts')])
        return inventory.get_groups_dict()[group]