# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# /*----------------------------------------------------------------------------8
# |                                                                            |
# |                          SAP Notes and Recomendations                       |
# |                                                                            |
# +------------------------------------4--------------------------------------*/

---

# -------------------------------------+---------------------------------------8
#
# Task: 2.10      - SAP Notes and Recomendations
#
# Implement manual preparation steps for all OS
# The tasks' name follows:
#   - SAP Notes for RHEL OS recommendations
#
# -------------------------------------+---------------------------------------8

# -------------------------------------+---------------------------------------8
#
# Task: 2.10.0    - SAP Note 2205917 - SAP HANA DB Recommended OS settings for
#                   SLES 12 / SLES for SAP Applications 12
#
# TODO: 20210128 review the RHEL stuff and the SAP Note
# RHEL-3.10 Disable Transparent Hugepages (THP)
# RHEL-3.12 Configure Processor C-States (not relevant for IBM Power LE (ppc64le))

- name:                                2.10.0 - SAP Note 2205917
  ansible.builtin.include_tasks:       2.10.0.yaml
  when:
    - node_tier == 'hana'
    - distribution_id in ['suse12', 'suse15', 'sles_sap12', 'sles_sap15']

# -------------------------------------+---------------------------------------8

# -------------------------------------+---------------------------------------8
#
# Task: 2.10.1   - SAP Note 2777782 - SAP HANA DB Recommended OS settings for
#                   RHEL 8
#
# Set 'sap-hana' as tuned profile
# Add GRUB arguments to the config
# Set 'never' for transparent_hugepage
# Disable SELinux
# Disable core file creation

- name:                                "2.10.1 sap-notes: - Disable SELinux and Reboot"
  when:
    - node_tier in ['scs', 'ers', 'pas', 'app', 'web']
    - distribution_id in ['redhat7', 'redhat8', 'redhat9']
  block:
    - name:                            "2.10.1 sap-notes: - Disable SELinux"
      ansible.posix.selinux:
        state:                         disabled
      register:                        selinux_disabled

    - name:                            "2.10.1 sap-notes: Reboot app VMs after selinux is configured"
      become:                          true
      become_user:                     root
      ansible.builtin.reboot:
        reboot_timeout:                300
        post_reboot_delay:             60
      ignore_unreachable:              true
      failed_when:                     false
      when:
        - selinux_disabled.changed

    - name:                            "2.10.1 sap-notes: - Clear the failed state of hosts"
      ansible.builtin.meta:            clear_host_errors

  # Wait for Connection after reboot
    - name:                            "2.10.1 sap-notes: - Wait for system to become reachable"
      ansible.builtin.wait_for_connection:
        delay:                         10
        timeout:                       300


- name:                                "2.10.1 sap-notes: Check VM Agent Status"
  when:
    - selinux_disabled.changed
    - node_tier in ['scs', 'ers', 'pas', 'app', 'web']
    - distribution_id in ['redhat7', 'redhat8', 'redhat9']
  block:
    - name:                            "2.10.1 sap-notes: Clear the failed state of hosts"
      ansible.builtin.meta:            clear_host_errors

    - name:                            "2.10.1 sap-notes: Including Task for VM Agent Actions"
      ansible.builtin.include_tasks:   roles-misc/0.7-VmAgentActions/tasks/main.yaml
      vars:
        subscriptionId:                "{{ subscription_id }}"
        resourceGroup_name:            "{{ resource_group_name }}"
        vmName:                        "{{ vm_name }}"

    - name:                            "2.10.1 sap-notes: Wait for system to become reachable"
      ansible.builtin.wait_for_connection:
        timeout:                       300
      register:                        wait_for_connection_results

- name:                                "2.10.1 - SAP Note 2777782 tasks on RHEL OS"
  ansible.builtin.include_tasks:       2.10.1.yaml
  when:
    - node_tier == 'hana'
    - distribution_id in ['redhat8', 'redhat9']

- name:                                "2.10.2 - SAP Note 2777782 tasks on OEL OS"
  ansible.builtin.include_tasks:       2.10.2.yaml
  when:
    - node_tier in ['oracle', 'oracle-asm']
    - distribution_id == 'oraclelinux8'

- name:                                "2.10.1275776 - SAP Note 1275776 tasks on RHEL"
  ansible.builtin.include_tasks:       2.10.1275776.yaml
  when:
    - node_tier == 'sybase'
    - distribution_id in ['redhat8', 'redhat9']

- name:                                "2.10 - Force all notified handlers to run now"
  ansible.builtin.meta:                flush_handlers

- name:                                "2.10.3119751 - SAP Note 3119751 tasks on RHEL"
  ansible.builtin.include_tasks:       2.10.3119751.yaml
  when:
    - platform == 'HANA'
    - distribution_id in ['redhat8', 'redhat9']

# ToDo RHEL7 and also the other SAP nodes
# -------------------------------------+---------------------------------------8

- name:                                "2.10.3 - saptune for SLES 12 and SLES 15"
  ansible.builtin.include_tasks:       2.10.3.yaml
  when:
    - distribution_id in ['suse12', 'suse15', 'sles_sap12', 'sles_sap15']

# /*----------------------------------------------------------------------------8
# |                                    END                                      |
# +------------------------------------4--------------------------------------*/
