On Wed, 18 Mar 2020 07:28:27 -0700 (PDT)
Pandu jh <[email protected]> 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.
> 
> # cat AnsibleTest.csv
> ip,var1,var2
> 10.1.1.1,rchantif1,mechlab
> 10.1.1.2,rchans01,contlab

Read the the file and create new group of hosts in the first play. The use
the group in the second play. For example

shell> cat playbook.yml
- hosts: localhost
  gather_facts: false
  tasks:
    - read_csv:
        path: AnsibleTest.csv
      register: myhosts
    - add_host:
        name: '{{ item.ip }}'
        groups: test_01
        var1: "{{ item.var1 }}"
        var2: "{{ item.var2 }}"
      loop: "{{ myhosts.list }}"

- hosts: test_01
  gather_facts: false
  tasks:
    - debug:
        msg:
          - "{{ inventory_hostname }}"
          - "{{ var1 }}"
          - "{{ var2 }}"

shell> ansible-playbook playbook.yml
...
ok: [10.1.1.1] => {
    "msg": [
        "10.1.1.1", 
        "rchantif1", 
        "mechlab"
    ]
}
ok: [10.1.1.2] => {
    "msg": [
        "10.1.1.2", 
        "rchans01", 
        "contlab"
    ]
}

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/20200320232753.5d772d73%40gmail.com.

Attachment: pgpgxIqwtqqrx.pgp
Description: OpenPGP digital signature

Reply via email to