---

- name: Check if the hard limit of nofile for group sapsys is 1048576
  command: awk '/sapsys/&&/nofile/&&/hard/{print $NF}' /etc/security/limits.d/99-sap.conf
  register: __sap_preconfigure_register_limits_sap_conf_nofile_hard_assert
  changed_when: no
  ignore_errors: yes
  when:
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.exists
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.isreg

- name: Assert that the hard limit of nofile for group sapsys is 1048576
  assert:
    that: "__sap_preconfigure_register_limits_sap_conf_nofile_hard_assert.stdout == '1048576'"
    fail_msg: "FAIL: The hard limit of nofile for group 'sapsys' in /etc/security/limits.d/99-sap.conf is
               '{{ __sap_preconfigure_register_limits_sap_conf_nofile_hard_assert.stdout }}' but the expected value is 1048576 !"
    success_msg: "PASS: The hard limit of nofile for group 'sapsys' in /etc/security/limits.d/99-sap.conf is
                  '{{ __sap_preconfigure_register_limits_sap_conf_nofile_hard_assert.stdout }}'."
  ignore_errors: "{{ sap_preconfigure_assert_ignore_errors|d(false) }}"
  when:
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.exists
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.isreg

- name: Check if the soft limit of nofile for group sapsys is 1048576
  command: awk '/sapsys/&&/nofile/&&/soft/{print $NF}' /etc/security/limits.d/99-sap.conf
  register: __sap_preconfigure_register_limits_sap_conf_nofile_soft_assert
  changed_when: no
  ignore_errors: yes
  when:
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.exists
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.isreg

- name: Assert that the soft limit of nofile for group sapsys is 1048576
  assert:
    that: "__sap_preconfigure_register_limits_sap_conf_nofile_soft_assert.stdout == '1048576'"
    fail_msg: "FAIL: The soft limit of nofile for group 'sapsys' in /etc/security/limits.d/99-sap.conf is
               '{{ __sap_preconfigure_register_limits_sap_conf_nofile_soft_assert.stdout }}' but the expected value is 1048576 !"
    success_msg: "PASS: The soft limit of nofile for group 'sapsys' in /etc/security/limits.d/99-sap.conf is
                  '{{ __sap_preconfigure_register_limits_sap_conf_nofile_soft_assert.stdout }}'."
  ignore_errors: "{{ sap_preconfigure_assert_ignore_errors|d(false) }}"
  when:
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.exists
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.isreg

- name: Get the hard limit of nofile for the database group
  command: awk '/@{{ sap_preconfigure_db_group_name }}/&&/nofile/&&/hard/{print $NF}' /etc/security/limits.d/99-sap.conf
  register: __sap_preconfigure_register_limits_sap_conf_db_group_nofile_hard_assert
  changed_when: no
  ignore_errors: yes
  when:
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.exists
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.isreg
    - sap_preconfigure_db_group_name is defined

- name: Assert that the hard limit of nofile for the database group is 1048576
  assert:
    that: "__sap_preconfigure_register_limits_sap_conf_db_group_nofile_hard_assert.stdout == '1048576'"
    fail_msg: "FAIL: The hard limit of nofile for group '{{ sap_preconfigure_db_group_name }}' is not set to '1048576' in /etc/security/limits.d/99-sap.conf!"
    success_msg: "PASS: The hard limit of nofile for group '{{ sap_preconfigure_db_group_name }}' is set to '1048576' in /etc/security/limits.d/99-sap.conf."
  ignore_errors: "{{ sap_preconfigure_assert_ignore_errors|d(false) }}"
  when:
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.exists
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.isreg
    - sap_preconfigure_db_group_name is defined

- name: Get the soft limit of nofile for the database group
  command: awk '/@{{ sap_preconfigure_db_group_name }}/&&/nofile/&&/soft/{print $NF}' /etc/security/limits.d/99-sap.conf
  register: __sap_preconfigure_register_limits_sap_conf_db_group_nofile_soft_assert
  changed_when: no
  ignore_errors: yes
  when:
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.exists
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.isreg
    - sap_preconfigure_db_group_name is defined

- name: Assert that the soft limit of nofile for the database group is 1048576
  assert:
    that: "__sap_preconfigure_register_limits_sap_conf_db_group_nofile_soft_assert.stdout == '1048576'"
    fail_msg: "FAIL: The soft limit of nofile for group '{{ sap_preconfigure_db_group_name }}' is not set to '1048576' in /etc/security/limits.d/99-sap.conf!"
    success_msg: "PASS: The soft limit of nofile for group '{{ sap_preconfigure_db_group_name }}' is set to '1048576' in /etc/security/limits.d/99-sap.conf."
  ignore_errors: "{{ sap_preconfigure_assert_ignore_errors|d(false) }}"
  when:
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.exists
    - __sap_preconfigure_register_stat_limits_sap_conf_assert.stat.isreg
    - sap_preconfigure_db_group_name is defined
