Want to iterate through the items and print teh corressponding mac address.
On Tuesday, July 2, 2019 at 9:15:55 AM UTC+5:30, Rakesh Parida wrote:
>
> 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",
> "x1.x1.x1.x1",
> "x2.x2.x2.x2"
> ]
> },
> "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 Regards
> Rakesh
>
> On Monday, July 1, 2019 at 8:25:07 PM UTC+5:30, Tanisha Mishra wrote:
>>
>> Can you share the error ?
>>
>> On Monday, July 1, 2019 at 6:44:44 PM UTC+5:30, Rakesh Parida wrote:
>>>
>>>
>>> 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 }}"
>>>
>>
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/3662286b-de11-4b5f-89db-0d641f2715b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.