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/855f9d99-2e53-4354-ba0c-4de7c1a788ef%40googlegroups.com.

Reply via email to