---
# OS RELEASE: RHEL 7
# Platform: PPC64LE
# SAP Note: 2055470
# https://launchpad.support.sap.com/#/notes/2055470
# The SAP Note points to http://www-03.ibm.com/support/techdocs/atsmastr.nsf/WebIndex/WP102502

# On the above page you will find more PDF documents, the following is used in this config file:
# Configuring your Network for SAP HANA (Ethernet connectivity):
# http://www-03.ibm.com/support/techdocs/atsmastr.nsf/5cb5ed706d254a8186256c71006d2e0a/c32b40501f4f76c886257de0004fa1d4/$FILE/
#    Network_Configuration_for_HANA_Workloads_on_IBM_Power_Servers_V4.pdf

- name: Perform configuration changes for ppc64le
  block:

    - name: Configure - Display SAP note number 2055470 and its version
      debug:
        msg: "SAP note {{ (__sap_hana_preconfigure_sapnotes_versions | selectattr('number', 'match', '^2055470$') | first).number }}
              (version {{ (__sap_hana_preconfigure_sapnotes_versions | selectattr('number', 'match', '^2055470$') | first).version }}): SAP HANA on POWER settings"

    - name: Ensure MTU size is 9000 on all interfaces
      shell: |
        mtu=$(nmcli conn show {{ line_item }} | grep 802-3-ethernet.mtu | awk -F: '{printf("%d", $2)}')
        if [ "$mtu" != "9000" ]; then
           nmcli conn mod {{ line_item }} 802-3-ethernet.mtu "9000"
           ip link set mtu 9000 dev {{ line_item }}
        else
           exit 90
        fi
      register: __sap_hana_preconfigure_register_ibm_mtusize
      changed_when: __sap_hana_preconfigure_register_ibm_mtusize is success
      failed_when: __sap_hana_preconfigure_register_ibm_mtusize.rc > 0 and __sap_hana_preconfigure_register_ibm_mtusize.rc != 90
      with_items: "{{ sap_hana_preconfigure_ppcle_mtu9000_if }}"
      when: not(
              (sap_hana_preconfigure_ppcle_mtu9000_if is undefined) or
              (sap_hana_preconfigure_ppcle_mtu9000_if is none) or
              (sap_hana_preconfigure_ppcle_mtu9000_if | trim | length == 0)
            )
      loop_control:
        loop_var: line_item

# This only works if interfacename=device name, otherwise it fails
    - name: Add largesend options to interfaces
      lineinfile:
        path: /etc/sysconfig/network-scripts/ifcfg-{{ line_item }}
        regexp: '^ETHTOOL_OPTIONS_tso='
        line: ETHTOOL_OPTIONS_tso='-K iface tso on'
      with_items: "{{ sap_hana_preconfigure_ppcle_tso_if }}"
      when: not(
              (sap_hana_preconfigure_ppcle_tso_if is undefined) or
              (sap_hana_preconfigure_ppcle_tso_if is none) or
              (sap_hana_preconfigure_ppcle_tso_if | trim | length == 0)
            )
      loop_control:
        loop_var: line_item
      ignore_errors: true

    - name: Add largesend kernel parameters for ppc64le
      lineinfile:
        path: /etc/sysctl.d/ibm_largesend.conf
        create: yes
        mode: 0644
        regexp: ^{{ line_item.name }}.*
        line: "{{ line_item.name }}={{ line_item.value }}"
        state: present
      with_items: "{{ sap_hana_preconfigure_kernel_parameters_ppc64le }}"
      loop_control:
        loop_var: line_item

    - name: Reload kernel parameters from file '/etc/sysctl.d/ibm_largesend.conf'
      command: sysctl -p /etc/sysctl.d/ibm_largesend.conf
      register: __sap_hana_preconfigure_register_ibm_largesend_sysctl_p_output

    - name: Display largesend kernel parameters
      debug:
        var: __sap_hana_preconfigure_register_ibm_largesend_sysctl_p_output.stdout_lines

  when: ansible_architecture == 'ppc64le'
