The best way to do this is to make GET requests to the api/v2/hosts endpoint, then parse that json to get he relevant fields/data and write them to a .csv
You can also do this with awx collection, which can also output to json
Try that out and let us know if you run into problems along the way, happy to help further
AWX Team