# list all MAC addresses through ansible

**URL:** <https://forum.ansible.com/t/list-all-mac-addresses-through-ansible/16348>\
**Category:** Ansible Project\
**Created:** [September 25, 2014, 9:40pm UTC](https://forum.ansible.com/t/list-all-mac-addresses-through-ansible/16348 "2014-09-25T21:40:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle\_Hopfensperger](https://avatars.discourse-cdn.com/v4/letter/k/76d3ee/32.png) [@Kyle\_Hopfensperger](https://forum.ansible.com/u/Kyle_Hopfensperger)\
**Post date:** [September 25, 2014, 9:40pm UTC](https://forum.ansible.com/t/list-all-mac-addresses-through-ansible/16348/1 "2014-09-25T21:40:17Z")

</div>

Hello,

I am wondering if there is a way to list all MAC addresses assigned to each interface device found through setup? What I am looking to do is edit the /etc/udev/rules.d/70-persistent-net.rules file to assign each detected interface after eth0 and apply the MAC address associated with it. It works perfectly for /etc/network/interfaces ( [https://gist.github.com/analytically/5760207](https://gist.github.com/analytically/5760207) ). If there isn’t a way I can always create a script, but I feel its safer to go through ansible on updating this instead of running a script each time the playbook is ran.

Thanks,  
Kyle

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 26, 2014, 12:22pm UTC](https://forum.ansible.com/t/list-all-mac-addresses-through-ansible/16348/2 "2014-09-26T12:22:40Z")

</div>

Dumping a given fact for all hosts could be done something like this:

- hosts: all  
gather\_facts: True  
tasks: 

- hosts: localhost  
tasks:

- template: src=maclist.j2 dest=/tmp/maclist.j2

{% for host in groups[‘all’] % }  
{{ host }} - {{ hostvars[host][‘whatever\_variable’] }}  
{% endfor %}

This was typed quickly and may have a typo in it.

See “ansible hostname -m setup” to list all facts available for a host.

Some extra template logic would be necessary to walk the network interfaces.
