--- /dev/null
+---
+- name: Make sure ethtool is installed
+ package:
+ name: ethtool
+ state: latest
+
+- name: grep ethtool for secondary NIC MAC address
+ shell: "ethtool -P {{ item }} | awk '{ print $3 }' | grep -q -i '{{ secondary_nic_mac }}'"
+ register: ethtool_grep_output
+ with_items: "{{ ansible_interfaces }}"
+ failed_when: false
+ changed_when: false
+
+- name: Define net_to_configure var
+ set_fact:
+ nic_to_configure: "{{ item.item }}"
+ with_items: "{{ ethtool_grep_output.results }}"
+ when: item.rc == 0
+
+# Default to 1500
+- set_fact: mtu=1500
+
+- name: "Check if {{ nic_to_configure }} is 10Gb"
+ shell: "ethtool {{ nic_to_configure }} | grep Speed | awk '{ print $2 }'"
+ register: nic_to_configure_speed
+ changed_when: false
+
+# Assume jumbo frames if 10Gb
+- name: Set MTU to 9000 if 10Gb
+ set_fact: mtu=9000
+ when:
+ - nic_to_configure_speed is defined
+ - nic_to_configure_speed.stdout == '10000Mb/s'
+
+- name: "Write Ubuntu network config for {{ nic_to_configure }}"
+ blockinfile:
+ path: /etc/network/interfaces
+ block: |
+ auto {{ nic_to_configure }}
+ iface {{ nic_to_configure }} inet dhcp
+ register: wrote_network_config
+ when:
+ - nic_to_configure is defined
+ - ansible_os_family == 'Debian'
+
+# Can't set MTU for DHCP interfaces on Ubuntu in /etc/network/interfaces
+- name: Set MTU on Ubuntu
+ shell: "ifconfig {{ nic_to_configure }} mtu {{ mtu }}"
+ when: ansible_os_family == 'Debian'
+
+- name: "Bounce {{ nic_to_configure }}"
+ shell: "ifdown {{ nic_to_configure }} && ifup {{ nic_to_configure }}"
+ when:
+ - wrote_network_config|changed
+ - ansible_os_family == 'Debian'
+
+- name: "Write RHEL/CentOS network config for {{ nic_to_configure }}"
+ lineinfile:
+ path: "/etc/sysconfig/network-scripts/ifcfg-{{ nic_to_configure }}"
+ create: yes
+ owner: root
+ group: root
+ mode: 0644
+ regexp: "{{ item.regexp }}"
+ line: "{{ item.line }}"
+ register: wrote_network_config
+ with_items:
+ - { regexp: '^DEVICE=', line: 'DEVICE={{ nic_to_configure }}' }
+ - { regexp: '^BOOTPROTO=', line: 'BOOTPROTO=dhcp' }
+ - { regexp: '^ONBOOT=', line: 'ONBOOT=yes' }
+ - { regexp: '^MTU=', line: 'MTU={{ mtu }}' }
+ when:
+ - nic_to_configure is defined
+ - ansible_os_family == 'RedHat'
+
+- name: "Bounce {{ nic_to_configure }}"
+ shell: "ifdown {{ nic_to_configure }} && ifup {{ nic_to_configure }}"
+ when:
+ - wrote_network_config|changed
+ - ansible_os_family == 'RedHat'