---
# handlers file for sap-preconfigure

- name: Reboot the managed node
  reboot:
    test_command: /bin/true
  listen: __sap_preconfigure_reboot_handler
  when:
    - sap_preconfigure_reboot_ok|d(false)

- name: Let the role fail if a reboot is required
  fail:
    msg: Reboot is required!
  listen: __sap_preconfigure_reboot_handler
  when:
    - sap_preconfigure_fail_if_reboot_required|d(true)
    - not sap_preconfigure_reboot_ok|d(false)

- name: Show a warning message if a reboot is required
  debug:
    msg: "WARN: Reboot is required!"
  listen: __sap_preconfigure_reboot_handler
  when:
    - not sap_preconfigure_fail_if_reboot_required|d(true)
    - not sap_preconfigure_reboot_ok|d(false)

- name: Set the flag that reboot is needed to apply changes
  set_fact:
    sap_preconfigure_fact_reboot_required: true
  listen: __sap_preconfigure_reboot_handler
  when:
    - not sap_preconfigure_fail_if_reboot_required|d(true)
    - not sap_preconfigure_reboot_ok|d(false)

- name: Remount /dev/shm
  command: mount -o remount /dev/shm
  args:
    warn: false
  listen: __sap_preconfigure_mount_tmpfs_handler

- name: Check if /dev/shm is available
  command: df -h /dev/shm
  register: __sap_preconfigure_command_df_shm_result
  listen: __sap_preconfigure_mount_tmpfs_handler

- name: Show the result of df -h /dev/shm
  debug:
    var: __sap_preconfigure_command_df_shm_result.stdout_lines, __sap_preconfigure_command_df_shm_result.stderr_lines
  listen: __sap_preconfigure_mount_tmpfs_handler
