'Gets host from MDT Database'

def get_hosts(self, hostname=False):

    if hostname:
        query = ("SELECT    t1.ID,    t1.Description,    t1.MacAddress,    t2.Role    FROM    ComputerIdentity    as    t1    join    Settings_Roles    as    t2    on    t1.ID    =    t2.ID    where    t1.Description    =    '%s'" % hostname)
    else:
        query = 'SELECT    t1.ID,    t1.Description,    t1.MacAddress,    t2.Role    FROM    ComputerIdentity    as    t1    join    Settings_Roles    as    t2    on    t1.ID    =    t2.ID'
    self._connect(query)
    groupname = self.mdt_groupname
    hostlist = []
    for hosts in self.mdt_dump:
        self.inventory['_meta']['hostvars'][hosts[1]] = {'id': hosts[0], 'name': hosts[1], 'mac': hosts[2], 'role': hosts[3]}
        hostlist.append(hosts[1])
    self.inventory[groupname] = hostlist
    print json.dumps(self.inventory, indent=2)
