I have a CSV file that contains the IP’s and it’s variables.
I need to use the details to log in to the host and use the respective variable’s value of the specfic IP’s.
My csv file looks like this and its called ip.csv:
ip,username,host
10.1.1.1,rchantif1,mechlab
10.1.1.2,rchans01,contlab
192.168.2.142,vagrant
I’m using the read_csv: module to access the data
What I did is create a playbook that prints what you are looking for the then I followed up on another task an example of logging into a host with the username and IP. I’m not 100% sure what you want to do but hopefully with the info I provided you have a start to your playbook/tasks.
I have a CSV file that contains the IP's and it's variables.
I need to use the details to log in to the host and use the respective
variable's value of the specfic IP's.
thanks Vladimir, your suggestion helped a lot. Still, i am facing one challenge while using add_host. I have the csv file with the same server has different volumes. When i run the playbook, it is displaying last entry associated to the same but i would like to display all the entries. Can you suggest on the same?
the playbook is working if the csv has single entry associated to the host, but same playbook is failing if the same host has multiple variables entries. I tried many ways by using inventory but no luck. Finally, i choose read_csv and add_host. If you have working example with inventory, can you please share with me?
Initially, i tried your approach but engineer has to do more work to make the format as we are planning to use playbook for nfs volume migration. we have 1000’s of servers with 100’s volumes. Hence, the reason, we chosen the csv format. I have been using inventory based host connection but it is connecting even if volume is not required to mount/unmount on target host.
I have one more last question on the same request as we have different python interpreter on some hosts. Is it possible to read the python interpreter variable from CSV file while connecting the particular?
Prior to your solution, i use to use inventory to pass the variable to the host as below. Now, i want to omit inventory file as i would like to use your solution completely for host inventory. Can you please suggest same to overcome this problem other than declaring variables host_vars?
I have one more last question on the same request as we have different
python interpreter on some hosts. Is it possible to read the python
interpreter variable from CSV file while connecting the particular?
Prior to your solution, i use to use inventory to pass the variable to the
host as below. Now, i want to omit inventory file as i would like to use
your solution completely for host inventory. Can you please suggest same to
overcome this problem other than declaring variables host_vars?
Yes. It's possible. Simply put the path to Python into the CSV file. For
example, put it into the first record of the particular host. Various paths
don't make sense. Right?
I tried using the logic, and it worked when apply the values to debug but the same data is passing to mount module with additional quotes and brackets which is causing the errors. Any suggestions please?