import csv

all_vars="""
all:
  vars:
      ansible_network_os: arubanetworks.aoscx.aoscx
      ansible_connection: arubanetworks.aoscx.aoscx  # REST API via pyaoscx connection method
      ansible_aoscx_validate_certs: False
      ansible_aoscx_use_proxy: False
      ansible_acx_no_proxy: True
      ansible_ssh_common_args: "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
"""

building_dict={}

with open('central-inventory.csv') as csv_file:
    csv_reader = csv.DictReader(csv_file)
    for row in csv_reader:
        device_name=row["DEVICE NAME"]
        ip_address=row['IP ADDRESS']
        config_status=row['CONFIG STATUS']
        if config_status=='In sync':
            building=device_name.split("-")[0]
            if building not in building_dict:
                building_dict[building]=[]
            building_dict[building].append((device_name,ip_address))

#print(building_dict)
for building in building_dict:
    print(f"{building}:")
    print(f"  hosts:")
    for device_name,ip_address in building_dict[building]:
        print(f"    {device_name}:")
        print(f"      ansible_host: {ip_address}")
        print(f"      building_name: {building}")
print(all_vars)
