Launch instances from a file

38 views
Skip to first unread message

shyam...@gmail.com

unread,
Mar 25, 2019, 11:59:36 PM3/25/19
to Ansible Project
Hi,

I want to launch instances from a file. The file contains the variables like "InstanceName", HttpPortnumber and Portnumber and I want to pass this file as a Input parameter to the playbook to launch the instances on server.

can any one help.


Example file: 

InstanceName  HttpPortnumber  Portnumber

Sample1            1122                   2211
Sample2            1233                   4321
sample3             4432                   3321


Thank you,
Shyam

Sudheer Satyanarayana

unread,
Mar 26, 2019, 12:52:54 AM3/26/19
to ansible...@googlegroups.com

You can read the file contents using the lookup plugin. Once you have the file contents, you can then try to apply regex filter to obtain the pattern you need.

Is it possible to use a more structured format like JSON instead of text file like the one you have? That would make the task a lot easier.


--
Sudheer Satyanarayana
System Administrator And Developer
Tech Chorus - https://www.techchorus.net

shyam...@gmail.com

unread,
Mar 26, 2019, 1:46:12 PM3/26/19
to Ansible Project
Hi Sudheer,

Thanks for your update. I want to read the file line by line. is it possible to do through Ansible ?

I have tried with Lookup plugin and Im able to save the instance name, HTTP port number and Portnumber in a separate vaiable from CSV file.

Here my requirement is to iterate the CSV file contents line by line and need to launch the instances from the CSV file.

Any suggestions please.

Thank you,
Shyam 

Sudheer Satyanarayana

unread,
Mar 27, 2019, 1:58:41 AM3/27/19
to ansible...@googlegroups.com


On 26/03/19 11:16 PM, shyam...@gmail.com wrote:
Hi Sudheer,
Thanks for your update. I want to read the file line by line. is it possible to do through Ansible ?
I have tried with Lookup plugin and Im able to save the instance name, HTTP port number and Portnumber in a separate vaiable from CSV file.
So, you are already reading the file and fetching the details you want?

Here my requirement is to iterate the CSV file contents line by line and need to launch the instances from the CSV file.

If you have a CSV file, us the read_csv module.

https://docs.ansible.com/ansible/devel/modules/read_csv_module.html

Reply all
Reply to author
Forward
0 new messages