Hi Suresh, On Thu, 9 Apr 2020 17:46:42 +0530 Suresh Karpurapu <[email protected]> wrote:
> 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
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?
shell> cat mounts.csv
host,remote_path,mnt_path,python
host1,nfsvol1,mount1,/usr/bin/python2.6
host1,nfsvol2,mount2
host1,nfsvol3,mount3
host2,nfsvol1,mount1,/usr/bin/python3.7
host2,nfsvol2,mount2
host2,nfsvol3,mount3
Then simply assign "ansible_python_interpreter in the first play
add_host:
name: "{{ item.0 }}"
groups: nfsgroup
var1: "{{ item.1|json_query('[].remote_path') }}"
var2: "{{ item.1|json_query('[].mnt_path') }}"
ansible_python_interpreter: "{{ item.1.0.python }}"
loop: "{{ sources.list|groupby('host') }}"
(It's not necessary to delegate_to localhost when the play is running at
localhost "hosts: localhost").
HTH,
vlado
> >> On Wed, 8 Apr 2020 19:55:04 +0530
> >> Suresh Karpurapu <[email protected]> wrote:
> >> >
> >> > # 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
> >> >
> >> > - 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.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"
> >> ]
> >> ]
> >> }
--
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/20200409172104.56f48c6a%40gmail.com.
pgpQZSbLrTRuc.pgp
Description: OpenPGP digital signature
