Compare commits

3 changed files with 151 additions and 135 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
# ansible-networkconfig # ansible-networkconfig
This repo is intended to be used as an ansible role This repo is intended to be used as an ansible role called network-config
+44 -7
View File
@@ -5,6 +5,8 @@
'ifenslave', 'ifenslave',
] ]
tags: interfaces tags: interfaces
when: ansible_distribution == "Ubuntu" and ansible_distribution_version != "22.04"
- name: Configure /etc/network/interfaces - name: Configure /etc/network/interfaces
template: template:
@@ -19,18 +21,39 @@
state: absent state: absent
tags: interfaces tags: interfaces
- name: Remove /etc/netplan/01-netcfg.yaml # - name: Get directory stats
file: # stat:
path: /etc/netplan/01-netcfg.yaml # path: "/etc/netplan"
state: absent # register: directory_stat
# - name: Delete directory
# file:
# path: "/etc/netplan"
# state: absent
# - name: Create directory
# file:
# path: "/etc/netplan"
# state: directory
# owner: "{{ directory_stat.stat.pw_name }}"
# group: "{{ directory_stat.stat.gr_name }}"
# mode: "{{ directory_stat.stat.mode }}"
- name: 'Collect files in netplan dir'
find:
paths: "/etc/netplan/"
hidden: True
recurse: True
# file_type: any # Added in ansible 2.3
register: collected_files
tags: interfaces tags: interfaces
- name: Remove /etc/netplan/50-cloud-init.yaml - name: Remove collected files
file: file:
path: /etc/netplan/50-cloud-init.yaml path: "{{ item.path }}"
state: absent state: absent
with_items: "{{ collected_files.files }}"
tags: interfaces tags: interfaces
- name: Add the bonding module - name: Add the bonding module
modprobe: modprobe:
name: bonding name: bonding
@@ -56,3 +79,17 @@
state: present state: present
line: 'bonding' line: 'bonding'
tags: interfaces tags: interfaces
- name: Make sure ip-tables makes it into /etc/modules for loading at boot time
lineinfile:
path: /etc/modules
state: present
line: 'ip-tables'
tags: interfaces
- name: Make sure ip6-tables makes it into /etc/modules for loading at boot time
lineinfile:
path: /etc/modules
state: present
line: 'ip6-tables'
tags: interfaces
+106 -127
View File
@@ -1,127 +1,106 @@
auto lo auto lo
iface lo inet loopback iface lo inet loopback
{% if host_loopback_IP is defined %} {% if host_loopback_IP is defined %}
auto lo:1 auto lo:1
iface lo:1 inet static iface lo:1 inet static
address {{host_loopback_IP}}/32 address {{host_loopback_IP}}/32
{% endif %} {% endif %}
{% if OOBNET_NIC is defined %} {% if OOBNET_NIC is defined %}
auto {{OOBNET_NIC}} auto {{OOBNET_NIC}}
allow-hotplug {{OOBNET_NIC}} allow-hotplug {{OOBNET_NIC}}
iface {{OOBNET_NIC}} inet static iface {{OOBNET_NIC}} inet {% if OOBNET_DHCP is defined and OOBNET_DHCP|lower == "true" %}dhcp{% else %}static
address {{OOBNET_IP}}/{{OOBNET_Netmask}} address {{OOBNET_IP}}/{{OOBNET_Netmask}}
{% if OOBNET_GW is defined %}gateway {{OOBNET_GW}}{% endif %} {% if OOBNET_GW is defined %}gateway {{OOBNET_GW}}{% endif %}
{% endif %} {% endif %}
{% endif %}
{% if autobgp_interfaces is defined %}
{% for item in autobgp_interfaces %} {% if autobgp_interfaces is defined %}
{% for item in autobgp_interfaces %}
auto {{ item['name'] }}
allow-hotplug {{ item['name'] }} auto {{ item['name'] }}
iface {{ item['name'] }} inet static allow-hotplug {{ item['name'] }}
address {{host_loopback_IP}}/32 iface {{ item['name'] }} inet {% if item['dhcp'] is defined and item['dhcp']|lower == "true" %}dhcp{% else %}static
{% if item['mtu'] is defined %} address {{host_loopback_IP}}/32
mtu {{ item['mtu'] }} {% endif %}
{% endif %} {% if item['mtu'] is defined %}
{% if item['force10G'] is defined and item['force10G']|lower == "true" %} mtu {{ item['mtu'] }}
#Force speed to 10G {% endif %}
post-up sudo ethtool -s {{ item['name'] }} autoneg off {% if item['force10G'] is defined and item['force10G']|lower == "true" %}
post-up sudo ethtool -s {{ item['name'] }} speed 10000 # Force speed to 10G
{% endif %} post-up sudo ethtool -s {{ item['name'] }} autoneg off
{% if item['force40G'] is defined and item['force40G']|lower == "true" %} post-up sudo ethtool -s {{ item['name'] }} speed 10000
#Force speed to 40G {% endif %}
pre-up sudo ethtool -s {{ item['name'] }} autoneg off {% if item['force40G'] is defined and item['force40G']|lower == "true" %}
pre-up sudo ethtool -s {{ item['name'] }} speed 40000 # Force speed to 40G
{% endif %} pre-up sudo ethtool -s {{ item['name'] }} autoneg off
{% if item['auto40G'] is defined and item['auto40G']|lower == "true" %} pre-up sudo ethtool -s {{ item['name'] }} speed 40000
#Auto speed {% endif %}
pre-up sudo /bin/ip link set down {{ item['name'] }} && sleep 1 {% if item['routes'] is defined %}
pre-up sudo ethtool -s {{ item['name'] }} speed 40000 duplex full autoneg on {% for route in item['routes'] %}
post-up sudo /bin/ip link set up {{ item['name'] }} up ip route add {{ route['network'] }} via {{ route['gateway'] }} || true
{% endfor %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if addressed_interfaces is defined and addressed_interfaces != [] %} {% if addressed_interfaces is defined and addressed_interfaces != [] %}
{% for item in addressed_interfaces %} {% for item in addressed_interfaces %}
auto {{ item['name'] }} auto {{ item['name'] }}
allow-hotplug {{ item['name'] }} allow-hotplug {{ item['name'] }}
iface {{ item['name'] }} inet static iface {{ item['name'] }} inet {% if item['dhcp'] is defined and item['dhcp']|lower == "true" %}dhcp{% else %}static
address {{item['ip_address']}}/{{item['ip_netmask']}} address {{item['ip_address']}}/{{item['ip_netmask']}}
{% if item['mtu'] is defined %} {% endif %}
mtu {{ item['mtu'] }} {% if item['mtu'] is defined %}
{% endif %} mtu {{ item['mtu'] }}
{% if item['ip_gateway'] is defined %} {% endif %}
gateway {{item['ip_gateway']}} {% if item['routes'] is defined %}
{% endif %} {% for route in item['routes'] %}
{% if item['force10G'] is defined and item['force10G']|lower == "true" %} up ip route add {{ route['network'] }} via {{ route['gateway'] }} || true
post-up sudo ethtool -s {{ item['name'] }} autoneg off {% endfor %}
post-up sudo ethtool -s {{ item['name'] }} speed 10000 {% endif %}
{% endif %}
{% endfor %}
{% endfor %} {% endif %}
{% endif %}
{% if bond_interfaces is defined and bond_interfaces != [] %}
{% if bond_interfaces is defined and bond_interfaces != [] %} {% for item in bond_interfaces %}
{% for item in bond_interfaces %} {% for slave in item['slaves'] %}
{% for slave in item['slaves'] %} auto {{slave['name']}}
auto {{slave['name']}} iface {{slave['name']}} inet manual
iface {{slave['name']}} inet manual bond-master {{ item['name'] }}
bond-master {{ item['name'] }} {% endfor %}
{% endfor %}
auto {{ item['name'] }}
auto {{ item['name'] }} iface {{ item['name'] }} inet {% if item['dhcp'] is defined and item['dhcp']|lower == "true" %}dhcp{% else %}{% if item['ip_address'] is defined %}static
{% if item['ip_address'] is defined %} address {{item['ip_address']}}/{{item['ip_netmask']}}
iface {{ item['name'] }} inet static {% else %}manual{% endif %}{% endif %}
address {{item['ip_address']}}/{{item['ip_netmask']}} {% if item['routes'] is defined %}
{% else %} {% for route in item['routes'] %}
iface {{ item['name'] }} inet manual up ip route add {{ route['network'] }} via {{ route['gateway'] }} || true
{% endif %} {% endfor %}
{% if item['ip_gateway'] is defined %} {% endif %}
gateway {{item['ip_gateway']}} {% endfor %}
{% endif %} {% endif %}
{% if item['mtu'] is defined %}
mtu {{ item['mtu'] }} {% if vlan_interfaces is defined and vlan_interfaces != [] %}
{% endif %} {% for item in vlan_interfaces %}
bond-mode active-backup auto {{ item['name'] }}
bond-miimon 100 iface {{ item['name'] }} inet {% if item['dhcp'] is defined and item['dhcp']|lower == "true" %}dhcp{% else %}{% if item['ip_address'] is defined %}static
bond-slaves none address {{item['ip_address']}}/{{item['ip_netmask']}}
{% endfor %} {% else %}manual{% endif %}{% endif %}
{% endif %} {% if item['routes'] is defined %}
{% for route in item['routes'] %}
up ip route add {{ route['network'] }} via {{ route['gateway'] }} || true
{% endfor %}
{% if vlan_interfaces is defined and vlan_interfaces != [] %} {% endif %}
{% for item in vlan_interfaces %} {% endfor %}
auto {{ item['name'] }} {% endif %}
{% if item['ip_address'] is defined %}
iface {{ item['name'] }} inet static {% if unused_interfaces is defined and unused_interfaces != [] %}
address {{item['ip_address']}}/{{item['ip_netmask']}} {% for item in unused_interfaces %}
{% else %} allow-hotplug {{ item['name'] }}
iface {{ item['name'] }} inet manual iface {{ item['name'] }} inet manual
{% endif %} {% endfor %}
{% if item['ip_gateway'] is defined %} {% endif %}
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 %}