Last active
July 31, 2023 11:52
-
-
Save analytically/5809111 to your computer and use it in GitHub Desktop.
Ansible interface bonding tasks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# {{ ansible_managed }} | |
# This file describes the network interfaces available on your system | |
# and how to activate them. For more information, see interfaces(5). | |
# The loopback network interface | |
auto lo | |
iface lo inet loopback | |
{% if ansible_interfaces|length > 2 %} | |
{% for interface in ansible_interfaces if interface != 'lo' and interface != 'bond0' %} | |
auto {{ interface }} | |
iface {{ interface }} inet manual | |
bond-master bond0 | |
{% endfor %} | |
# The primary (bonded) network interface | |
auto bond0 | |
iface bond0 inet static | |
address {{ ansible_default_ipv4.address }} | |
netmask {{ ansible_default_ipv4.netmask }} | |
gateway {{ ansible_default_ipv4.gateway }} | |
network {{ ansible_default_ipv4.network }} | |
# bond0 uses standard IEEE 802.3ad LACP bonding protocol | |
bond-mode 802.3ad | |
bond-slaves none | |
# Indicates that the devices are polled every 250ms to check for connection changes, such as | |
# a link being down or a link duplex having changed | |
bond-miimon 200 | |
# Sets the rate for transmitting LACPDU packets, 0 is once every 30 seconds, 1 is every 1 second, which allows our | |
# network devices to automatically configure a single logical connection at the switch quickly | |
bond-lacp-rate 1 | |
# Instructs the driver to spread the load over interfaces based on the source and destination | |
# IP address instead of MAC address | |
bond-xmit-hash-policy layer3+4 | |
{% endif %} | |
{% if ansible_interfaces|length == 2 %} | |
# The primary network interface | |
auto {{ ansible_default_ipv4.interface }} | |
iface {{ ansible_default_ipv4.interface }} inet static | |
address {{ ansible_default_ipv4.address }} | |
netmask {{ ansible_default_ipv4.netmask }} | |
gateway {{ ansible_default_ipv4.gateway }} | |
network {{ ansible_default_ipv4.network }} | |
{% endif %} | |
dns-nameservers 8.8.8.8 8.8.4.4 | |
# the end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Make sure ifenslave-2.6 is installed | |
apt: pkg=ifenslave-2.6 | |
- name: Make sure bonding is a kernel module in /etc/modules | |
template: src=modules dest=/etc/modules | |
- name: Make sure /etc/network/interfaces has the correct bonding configuration | |
template: backup=yes src=interfaces dest=/etc/network/interfaces | |
- name: Make sure we reboot after bonding the interfaces | |
shell: /sbin/reboot | |
async: 45 | |
poll: 0 | |
- name: Wait for the server to reboot | |
wait_for: delay=20 port=22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# {{ ansible_managed }} | |
# /etc/modules: kernel modules to load at boot time. | |
# | |
# This file contains the names of kernel modules that should be loaded | |
# at boot time, one per line. Lines beginning with "#" are ignored. | |
loop | |
rtc | |
bonding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: all | |
sudo: true | |
roles: | |
- { role: nic_bonding, when: "ansible_interfaces|length > 2 and 'bond0' not in ansible_interfaces" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment