list all MAC addresses through ansible

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 ). 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

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.