ansible: get macaddress of connection_name: "Ethernet" (Windows Host)

  ansible, ansible-facts, jinja2, windows

I would like to rename a Windows Host by mac address.
I have a csv file with MAC;HOSTNAME.

I am at the step to get the macaddress of the connection named "Ethernet".

when i do ansible -m setup […] i get the following:

        "ansible_interfaces": [
        {
            "connection_name": "Ethernet",
            "default_gateway": "192.168.92.1",
            "dns_domain": null,
            "interface_index": 12,
            "interface_name": "Intel(R) Ethernet Connection (6) I219-LM",
            "macaddress": "A4:AE:11:1C:D5:7F"
        },
        {
            "connection_name": "WLAN",
            "default_gateway": null,
            "dns_domain": null,
            "interface_index": 18,
            "interface_name": "Intel(R) Wireless-AC 9560 160MHz",
            "macaddress": "8C:C6:81:63:34:45"
        },
        {
            "connection_name": "LAN-Verbindung* 1",
            "default_gateway": null,
            "dns_domain": null,
            "interface_index": 15,
            "interface_name": "Microsoft Wi-Fi Direct Virtual Adapter",
            "macaddress": "8C:C6:81:63:34:46"
        },
        {
            "connection_name": "LAN-Verbindung* 10",
            "default_gateway": null,
            "dns_domain": null,
            "interface_index": 9,
            "interface_name": "Microsoft Wi-Fi Direct Virtual Adapter #2",
            "macaddress": "8E:C6:81:63:34:45"
        },
        {
            "connection_name": "Bluetooth-Netzwerkverbindung",
            "default_gateway": null,
            "dns_domain": null,
            "interface_index": 10,
            "interface_name": "Bluetooth Device (Personal Area Network)",
            "macaddress": "8C:C6:81:63:34:49"
        }

How can i put the "maccaddress" of the correct interface in a variable?
Is this a dict or an array?

Source: Windows Questions

LEAVE A COMMENT