[ansible-project]Collect hostnames in an array

50 views
Skip to first unread message

Prady A

unread,
Jun 20, 2023, 10:49:21 PM6/20/23
to ansible...@googlegroups.com
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 

Dick Visser

unread,
Jun 20, 2023, 11:18:55 PM6/20/23
to ansible...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEuB3ApQPotWX84oyr57a7qkE6B43yaKPxbCfP5Prw5kVvTwMQ%40mail.gmail.com.
--
Sent from Gmail Mobile

Prady A

unread,
Jun 20, 2023, 11:25:29 PM6/20/23
to ansible...@googlegroups.com
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 

Abhijeet Kasurde

unread,
Jun 20, 2023, 11:35:48 PM6/20/23
to ansible...@googlegroups.com
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



--
Thanks,
Abhijeet Kasurde

Prady A

unread,
Jun 20, 2023, 11:46:49 PM6/20/23
to ansible...@googlegroups.com
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 

Reply all
Reply to author
Forward
0 new messages