Hi Vladimir, 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?
host4 ansible_python_interpreter=/usr/bin/python2.6 Regards, Suresh On Wed, Apr 8, 2020 at 11:15 PM Suresh Karpurapu <[email protected]> wrote: > awesome, it really helped for my requirement. thank you so much Vladimir, > > Regards, > Suresh > > On Wed, Apr 8, 2020 at 9:53 PM Vladimir Botka <[email protected]> wrote: > >> On Wed, 8 Apr 2020 19:55:04 +0530 >> Suresh Karpurapu <[email protected]> wrote: >> >> > ... i would like to display all the entries. >> > >> > # cat mounts.csv >> > host,remote_path,mnt_path >> > host1,nfsvol1,mount1 >> > host1,nfsvol2,mount2 >> > host1,nfsvol3,mount3 >> > host2,nfsvol1,mount1 >> > host2,nfsvol2,mount2 >> > host2,nfsvol3,mount3 >> > >> > # cat mounts.yml >> > --- >> > - name: mount the nfsshare in client side >> > hosts: localhost >> > gather_facts: false >> > become: yes >> > tasks: >> > - name: reading volume info from csv >> > read_csv: >> > path: "{{ playbook_dir }}/mounts.csv" >> > register: sources >> > delegate_to: localhost >> > - name: Grouping host and volume information >> > add_host: >> > name: "{{ item.host }}" >> > groups: nfsgroup >> > var1: "{{ item.remote_path }}" >> > var2: "{{ item.mnt_path }}" >> > loop: "{{ sources.list }}" >> >> Use "groupby" filter. For example >> https://jinja.palletsprojects.com/en/master/templates/#groupby >> >> add_host: >> name: "{{ item.0 }}" >> groups: nfsgroup >> var1: "{{ item.1|json_query('[].remote_path') }}" >> var2: "{{ item.1|json_query('[].mnt_path') }}" >> loop: "{{ sources.list|groupby('host') }}" >> >> > - name: list volume details >> > hosts: nfsgroup >> > become: yes >> > gather_facts: false >> > tasks: >> > - debug: >> > msg: >> > - "{{ inventory_hostname }}" >> > - "{{ var1 }}" >> > - "{{ var2 }}" >> >> You should receive lists of "remote_path" and "mnt_path" in var1 and var2 >> respectively. >> >> ok: [host1] => { >> "msg": [ >> "host1", >> [ >> "nfsvol1", >> "nfsvol2", >> "nfsvol3" >> ], >> [ >> "mount1", >> "mount2", >> "mount3" >> ] >> ] >> } >> ok: [host2] => { >> "msg": [ >> "host2", >> [ >> "nfsvol1", >> "nfsvol2", >> "nfsvol3" >> ], >> [ >> "mount1", >> "mount2", >> "mount3" >> ] >> ] >> } >> >> HTH, >> >> -vlado >> > -- 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/CAHedzh%2BLUoy9VZxG61AuLVa9qQV0Vkyp_Zr48iAHgwGgg7ZFSg%40mail.gmail.com.
