list all MAC addresses through ansible

1,399 views
Skip to first unread message

Kyle Hopfensperger

unread,
Sep 25, 2014, 5:40:17 PM9/25/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Sep 26, 2014, 8:22:43 AM9/26/14
to ansible...@googlegroups.com
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.



--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/88599501-17eb-461f-b101-1a3f005a1831%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages