Collect hostnames in an array

Hi all

Pls help… need to collect all the hostnames in an array and pass that are art finally to an python script as an argument…so that I can process that python file with all hostname in a loop.

If any other way to doing it that would be certainly great…

Regards…
Prady

https://docs.ansible.com/ansible/latest/cli/ansible-inventory.html

Thank Dick…Thank you for your kindness…
Sorry if I confused. My intention is to run the playbook and get all the hostnames in a variable .

Like :
var=hostvars[ansible_hostname][‘ansible_hostname’]

With the above command I can fetch the hostname but how to append all the hostnames in an array so that finally I can pass that array to python script.

Regards

I would write an Ansible module from the Python script and do the rest in Ansible. Anyways, check https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#magic-variables for ansible_play_hosts and ansible_play_hosts_all

Thank you Abhijeet…
Actually I ve to add one role which can create an excel to automate with the hostnames in it…
so what I thought to gather all the hostnames and process them using a python script to update the excel and send the excel in mail.

Regards