Skip to content

Instantly share code, notes, and snippets.

@enko
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save enko/89a2a0b776aeaf1d0fa5 to your computer and use it in GitHub Desktop.

Select an option

Save enko/89a2a0b776aeaf1d0fa5 to your computer and use it in GitHub Desktop.
a playbook to configure a host only by its mac address
#!/usr/local/bin/python
def mac2ll(mac):
mac = mac.split(":")
mac.insert(3,'fe')
mac.insert(3,'ff')
mac[0] = str(int(mac[0]) ^ 6)
return "fe80::%s:%s:%s:%s" % ("".join(mac[0:2]),"".join(mac[2:4]),"".join(mac[4:6]),"".join(mac[6:8]))
class FilterModule(object):
''' Ansible network jinja2 filters '''
def filters(self):
return {
'mac2ll': mac2ll
}
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.122.{{ id }}
broadcast 192.168.122.255
netmask 255.255.255.0
gateway 192.168.122.1
iface eth0 inet6 static
address 2a01:4f8:200:2265:3:100::{{ id }}
netmask 64
gateway fe80::5054:ff:fe9f:c3e4
---
- hosts: linux_guests
vars:
ansible_ssh_host: "{{ mac|mac2ll }}%vtnet0"
tasks:
- name: write sysctl.conf to the disk
copy: src=../templates/network/sysctl.conf dest=/etc/sysctl.conf
- name: write resolv.conf to the disk
copy: src=../templates/network/resolv.conf dest=/etc/resolv.conf
- name: write /etc/network/interfaces
template: src=../templates/network/interfaces dest=/etc/network/interfaces
- name: write /root/startping.sh
copy: src=../templates/network/startping.sh dest=/root/startping.sh mode=u+rx
- name: Make sure tmux is installed
apt: name=tmux state=present
- name: restart networking
shell: "/sbin/ifdown eth0; /sbin/ifup eth0"
- name: start startping
command: "/root/startping.sh"
- name: install startping as cronjob
cron: name="startping" special_time="reboot" job="/root/startping.sh"
nameserver 192.168.122.1
search int.datenknoten.me
#!/bin/sh
tmux new-session -d -s ping
tmux select-pane -t ping
tmux send-keys "/bin/ping6 -i 10 2a01:4f8:200:2265:2::1" C-m
net.ipv6.conf.all.accept_ra=0
net.ipv6.conf.all.autoconf=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment