# CSV item validation through loop

**URL:** <https://forum.ansible.com/t/csv-item-validation-through-loop/30689>\
**Category:** Ansible Project\
**Created:** [July 1, 2019, 1:14pm UTC](https://forum.ansible.com/t/csv-item-validation-through-loop/30689 "2019-07-01T13:14:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [July 1, 2019, 1:14pm UTC](https://forum.ansible.com/t/csv-item-validation-through-loop/30689/1 "2019-07-01T13:14:43Z")

</div>

Hi,

I have a csv file which has all the ip address and the mac address in column (as shown below):

> VM1 | TBD | | | | x.x.x.x | 02:07:C0:A8:06:04 | x1.x1.x1.x1 | 02:07:0A:AE:CC:54 | x2.x2.x2.x2 | 02:07:0A:91:10:BB | x3.x3.x3.x3 | 02:07:AC:10:04:03 |
> 
> - | - | - | - | - | - | - | - | - | - | - | - | - |  
> VM2 | TBD | | | | y.y.y.y | 02:07:C0:A8:06:05 | y1.y1.y1.y1 | 02:07:0A:AE:CC:55 | y2.y2.y2.y2 | 02:07:0A:91:10:BC | y.3.y3.y3.y3 | 02:07:AC:10:04:04 |  
> VM3 | TBD | | | | z.z.z.z | 02:07:C0:A8:06:06 | z1.z1.z1.z1 | 02:07:0A:AE:CC:56 | z2.z2.z2.z2 | 02:07:0A:91:10:BD | z3.z3.z3.z3 | 02:07:AC:10:04:05 |

Now i want to check the ip and mac combinations of mentioned in CSV, My playbook is as follows. Want to iterate through all the ip and mac combination and display.  
but my iteration is unsuccessful. Pls help

- hosts: all  
tasks:

- name: All IPV4 address in system  
setup: filter=“ansible\_all\_ipv4\_addresses”  
register: all\_ipv4\_address

- debug:  
var: all\_ipv4\_address

- name: Ip vs Mac Inside CSV  
debug:  
msg: “The MAC address of {{ item }} is {{ lookup(‘csvfile’, ‘{{ item }} file={{ inventory\_data }} delimiter=,’) }}”  
with\_items:  
“{{ all\_ipv4\_address }}”

---

<div class="post-metadata">

**Author:** ![Tanisha\_Mishra](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@Tanisha\_Mishra](https://forum.ansible.com/u/Tanisha_Mishra)\
**Post date:** [July 1, 2019, 2:55pm UTC](https://forum.ansible.com/t/csv-item-validation-through-loop/30689/2 "2019-07-01T14:55:07Z")

</div>

Can you share the error ?

---

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [July 2, 2019, 3:45am UTC](https://forum.ansible.com/t/csv-item-validation-through-loop/30689/3 "2019-07-02T03:45:54Z")

</div>

Error as below(Removed actual ips): I guess the loop is not iterated as desired from CSV items. Pls help

sudo ansible-playbook mac-test1.yml -D -C --limit VM[1] -i …/…/lab-inventories/LAB2/hosts

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [VM1]

TASK [All IPV4 address in system] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [VM1]

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [VM1] =\> {  
“all\_ipv4\_address”: {  
“ansible\_facts”: {  
“ansible\_all\_ipv4\_addresses”: [  
“x.x.x.x”,  
“y.y.y.y”,  
“z.z.z.z”  
]  
},  
“changed”: false,  
“failed”: false  
}  
}

TASK [Ip vs Mac Inside CSV] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [VM1] =\> (item=failed) =\> {  
“msg”: “The MAC address of failed is ”  
}  
ok: [VM1] =\> (item=changed) =\> {  
“msg”: “The MAC address of changed is ”  
}  
ok: [VM1] =\> (item=ansible\_facts) =\> {  
“msg”: “The MAC address of ansible\_facts is ”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
VM1 : ok=4 changed=0 unreachable=0 failed=0

With RegardsRakesh

---

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [July 2, 2019, 4:00am UTC](https://forum.ansible.com/t/csv-item-validation-through-loop/30689/4 "2019-07-02T04:00:00Z")

</div>

Want to iterate through the items and print teh corressponding mac address.
