# Configure a network interface according to its macaddress

**URL:** <https://forum.ansible.com/t/configure-a-network-interface-according-to-its-macaddress/22378>\
**Category:** Ansible Project\
**Created:** [August 25, 2016, 5:40am UTC](https://forum.ansible.com/t/configure-a-network-interface-according-to-its-macaddress/22378 "2016-08-25T05:40:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Derrick\_Lin](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@Derrick\_Lin](https://forum.ansible.com/u/Derrick_Lin)\
**Post date:** [August 25, 2016, 5:40am UTC](https://forum.ansible.com/t/configure-a-network-interface-according-to-its-macaddress/22378/1 "2016-08-25T05:40:36Z")

</div>

Dear all,

I am implementing a task which should configure a network interface according to the macaddress.

For example:

“ansible\_eth1”: {  
“active”: true,  
“device”: “eth1”,  
“id”: “8000.0050568d1cf8”,  
“interfaces”: [  
“peth1”  
],  
“ipv4”: {  
“address”: “129.94.72.12”,  
“broadcast”: “129.94.72.63”,  
“netmask”: “255.255.255.192”,  
“network”: “129.94.72.0”  
},  
“ipv6”: [  
{  
“address”: “fe80::250:56ff:fe8d:1cf8”,  
“prefix”: “64”,  
“scope”: “link”  
}  
],  
“macaddress”: “00:50:56:8d:1c:f8”,  
“mtu”: 1500,  
“promisc”: false,  
“stp”: false,  
“type”: “bridge”  
},

The tricky part is, the device name (such as eth1) is not reliable, the OS may assign differently after reinstallation. So I can only rely on macaddress, then pass the device name to my shell script for configuration.

I attempted to work around with “when” and “with\_items” but got syntax error all the time. Can someone show the correct way to do this?

Cheers,  
Derrick
