Hi Pandu, 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?
# cat mounts.csv [ working as expected] host,remote_path,mnt_path host1,nfsvol1,mount1 host2,nfsvol2,mount2 host3,nfsvol3,mount3 # cat mounts.csv [ working, but it is considering last entry only] host,remote_path,mnt_path host1,nfsvol1,mount1 host1,nfsvol2,mount2 host1,nfsvol3,mount3 host2,nfsvol1,mount1 host2,nfsvol2,mount2 host2,nfsvol3,mount3 Regards, Suresh On Wed, Apr 8, 2020 at 8:09 PM Pandu jh <[email protected]> wrote: > Can you try to format your csv data to inventory as below. > > # cat mounts > host,remote_path,mnt_path > host1,nfsvol1,mount1 > host1,nfsvol2,mount2 > host1,nfsvol3,mount3 > host2,nfsvol1,mount1 > host2,nfsvol2,mount2 > host2,nfsvol3,mount3 > > On Saturday, 21 March 2020 00:35:05 UTC+5:30, J wrote: >> >> >> 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. >> >> >> >> --- >> >> - name: read items from csv and store as vars >> >> hosts: localhost >> >> become: false >> >> tasks: >> >> - name: read_csv >> >> read_csv: >> >> path: ip.csv >> >> register: ip >> >> - name: print csv items >> >> debug: >> >> msg: "{{ip.list.2.ip}} {{ip.list.2.username}} {{ip.list.2.host}}" >> >> - name: >> >> shell: "ssh {{ip.list.2.username}}@{{ip.list.2.ip}} 'ls -la'" >> >> >> >> >> >> >> >> >> On Wednesday, March 18, 2020 at 10:28:27 AM UTC-4, Pandu jh wrote: >> >>> 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. >>> >>> Please help me out with this. >>> >>> # cat AnsibleTest.csv >>> ip,var1,var2 >>> 10.1.1.1,rchantif1,mechlab >>> 10.1.1.2,rchans01,contlab >>> >> >> On Wednesday, March 18, 2020 at 10:28:27 AM UTC-4, Pandu jh wrote: >>> >>> 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. >>> >>> Please help me out with this. >>> >>> # cat AnsibleTest.csv >>> ip,var1,var2 >>> 10.1.1.1,rchantif1,mechlab >>> 10.1.1.2,rchans01,contlab >>> >> >> On Wednesday, March 18, 2020 at 10:28:27 AM UTC-4, Pandu jh wrote: >>> >>> 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. >>> >>> Please help me out with this. >>> >>> # cat AnsibleTest.csv >>> ip,var1,var2 >>> 10.1.1.1,rchantif1,mechlab >>> 10.1.1.2,rchans01,contlab >>> >> -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/c586db4f-82f6-4560-b567-9ca1f125e342%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/c586db4f-82f6-4560-b567-9ca1f125e342%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAHedzhJsQV0SZG_LPpQ%3DESh9eMhvcBE1LnWhtdMbM6wQjG_DAA%40mail.gmail.com.
