From 11608a239acae8e2de73e05befb903e7c1873265 Mon Sep 17 00:00:00 2001 From: Cory Hawkless Date: Thu, 30 Jul 2020 17:04:46 +0930 Subject: [PATCH] Some juicy bits --- handlers/main.yml | 4 ++ tasks/main.yml | 58 ++++++++++++++++++ templates/interfaces.j2 | 126 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 handlers/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/interfaces.j2 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..e53f4f0 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,4 @@ +--- + +- name: restart frr-docker + action: service name=frr-docker enabled=yes state=restarted diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..50efbcf --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,58 @@ +- name: Install required system packages + apt: name={{ item }} state=latest update_cache=yes + loop: [ + 'ifupdown', + 'ifenslave', + ] + tags: interfaces + +- name: Configure /etc/network/interfaces + template: + src: templates/interfaces.j2 + dest: /etc/network/interfaces + backup: yes + tags: interfaces + +- name: Remove /etc/network/interfaces.d/eth0 + file: + path: /etc/network/interfaces.d/eth0 + state: absent + tags: interfaces + +- name: Remove /etc/netplan/01-netcfg.yaml + file: + path: /etc/netplan/01-netcfg.yaml + state: absent + tags: interfaces + +- name: Remove /etc/netplan/50-cloud-init.yaml + file: + path: /etc/netplan/50-cloud-init.yaml + state: absent + tags: interfaces + +- name: Add the bonding module + modprobe: + name: bonding + state: present + tags: interfaces + +- name: Add the 8021q module + modprobe: + name: 8021q + state: present + tags: interfaces + +- name: Make sure 8021q\dot1q makes it into /etc/modules for loading at boot time + lineinfile: + path: /etc/modules + state: present + line: '8021q' + tags: interfaces + +- name: Make sure bonding makes it into /etc/modules for loading at boot time + lineinfile: + path: /etc/modules + state: present + line: 'bonding' + tags: interfaces diff --git a/templates/interfaces.j2 b/templates/interfaces.j2 new file mode 100644 index 0000000..e1da08c --- /dev/null +++ b/templates/interfaces.j2 @@ -0,0 +1,126 @@ +auto lo + iface lo inet loopback +{% if host_loopback_IP is defined %} +auto lo:1 +iface lo:1 inet static + address {{host_loopback_IP}}/32 +{% endif %} + +{% if OOBNET_NIC is defined %} +auto {{OOBNET_NIC}} +allow-hotplug {{OOBNET_NIC}} +iface {{OOBNET_NIC}} inet static + address {{OOBNET_IP}}/{{OOBNET_Netmask}} +{% endif %} + +{% if autobgp_interfaces is defined %} +{% for item in autobgp_interfaces %} + +auto {{ item['name'] }} +allow-hotplug {{ item['name'] }} +iface {{ item['name'] }} inet static + address {{host_loopback_IP}}/32 +{% if item['mtu'] is defined %} + mtu {{ item['mtu'] }} +{% endif %} +{% if item['force10G'] is defined and item['force10G']|lower == "true" %} + #Force speed to 10G + post-up sudo ethtool -s {{ item['name'] }} autoneg off + post-up sudo ethtool -s {{ item['name'] }} speed 10000 +{% endif %} +{% if item['force40G'] is defined and item['force40G']|lower == "true" %} + #Force speed to 40G + pre-up sudo ethtool -s {{ item['name'] }} autoneg off + pre-up sudo ethtool -s {{ item['name'] }} speed 40000 +{% endif %} +{% if item['auto40G'] is defined and item['auto40G']|lower == "true" %} + #Auto speed + pre-up sudo /bin/ip link set down {{ item['name'] }} && sleep 1 + pre-up sudo ethtool -s {{ item['name'] }} speed 40000 duplex full autoneg on + post-up sudo /bin/ip link set up {{ item['name'] }} + +{% endif %} +{% endfor %} +{% endif %} + +{% if addressed_interfaces is defined and addressed_interfaces != [] %} +{% for item in addressed_interfaces %} + +auto {{ item['name'] }} +allow-hotplug {{ item['name'] }} +iface {{ item['name'] }} inet static + address {{item['ip_address']}}/{{item['ip_netmask']}} +{% if item['mtu'] is defined %} + mtu {{ item['mtu'] }} +{% endif %} +{% if item['ip_gateway'] is defined %} + gateway {{item['ip_gateway']}} +{% endif %} +{% if item['force10G'] is defined and item['force10G']|lower == "true" %} + post-up sudo ethtool -s {{ item['name'] }} autoneg off + post-up sudo ethtool -s {{ item['name'] }} speed 10000 +{% endif %} + +{% endfor %} +{% endif %} + +{% if bond_interfaces is defined and bond_interfaces != [] %} +{% for item in bond_interfaces %} +{% for slave in item['slaves'] %} +auto {{slave['name']}} +iface {{slave['name']}} inet manual + bond-master {{ item['name'] }} +{% endfor %} + +auto {{ item['name'] }} +{% if item['ip_address'] is defined %} + iface {{ item['name'] }} inet static + address {{item['ip_address']}}/{{item['ip_netmask']}} +{% else %} + iface {{ item['name'] }} inet manual +{% endif %} +{% if item['ip_gateway'] is defined %} + gateway {{item['ip_gateway']}} +{% endif %} +{% if item['mtu'] is defined %} + mtu {{ item['mtu'] }} +{% endif %} + bond-mode active-backup + bond-miimon 100 + bond-slaves none +{% endfor %} +{% endif %} + + + +{% if vlan_interfaces is defined and vlan_interfaces != [] %} +{% for item in vlan_interfaces %} +auto {{ item['name'] }} +{% if item['ip_address'] is defined %} +iface {{ item['name'] }} inet static + address {{item['ip_address']}}/{{item['ip_netmask']}} +{% else %} + iface {{ item['name'] }} inet manual +{% endif %} +{% if item['ip_gateway'] is defined %} + gateway {{item['ip_gateway']}} +{% endif %} +{% if item['mtu'] is defined %} + mtu {{ item['mtu'] }} +{% endif %} + vlan-raw-device {{ item['vlan-raw-device'] }} +{% endfor %} +{% endif %} + + + + + + +{% if unused_interfaces is defined and unused_interfaces != [] %} +{% for item in unused_interfaces %} + +allow-hotplug {{ item['name'] }} +iface {{ item['name'] }} inet manual +{% endfor %} +{% endif %}