Jul-08-2020, 08:51 AM
hi,
usually a brainfart, but i need your sharp eyes as i'm stuck.
this function should iterate over a list, but only prints the first item than stops somewhat.
usually a brainfart, but i need your sharp eyes as i'm stuck.
this function should iterate over a list, but only prints the first item than stops somewhat.
def make_hostgroups(): group_names = get_hostgroups() print(group_names) for item in group_names: group = item query_left = """SELECT {} FROM ansible_hostgroups_view WHERE {} IS NOT NULL;""".format(group, group) result_left = r.run_query('left_connection', query_left) result_left = result_left[0] print(result_left) print(type(result_left)) for item in result_left: to_string = ",".join(map(str, item)) host = to_string.split(',')[0].replace('(','') print(host) sys.exit(1)output:
root@lpgaixmgmtlx01:/etc/ansible/aix/dyninv>./ansible_inv_pusher.py ['LNZ', 'WBG', 'GBG', 'VIE'] [('NGKK-T2',), ('AIXVAEBDBT',), ('AIXTSMREPL',), ('GRU0154_SECPOCDB',), ('AIXBUILDHOST',), ('AIXBUILDHOSTNG',), ('AIXSTP11R3APP',), ('STP17T1_SGKKT1',), ('HSR5S1P8_AM',), ('AIXTEST01',), ('HSR3S1P10_OOEGKKTEST',), ('AIXSAGRU3',), ('AIXSTP11R3DB',), ('AMTEST1',), ('AIXSTP12E3',), ('AIXSAGRU2',), ('OOEGKKT6',), ('ARR5S1P9_TIC',), ('AIXSAGRU4',), ('AIXAMTEST1DB',), ('ARR3S2P4_NOEGKKTEST',), ('HSR1S6P3_DBATEST',), ('HSR5S1P6_NIM',), ('HSR3S2P6_OOEGKKTEST',), ('HSR5S1P9_STGKKTEST',), ('TSM-LINZ',), ('HSR2S1P2_LGKKCC',), ('HSR5S2P10_ORAGRIDCL',), ('ARR5S1P8_OOEGKKPR',), ('STP17T2_SGKKT2',), ('ARR3S2P6_STGKKTEST',)] <class 'list'> NGKK-T2so what might be the problem here?