---

# loop block for sapnote/RedHat/generic/assert-kernel-parameters.yml

- name: Get {{ line_item.name }} from {{ __sap_preconfigure_etc_sysctl_sap_conf }}
  shell: awk 'BEGIN{FS="="}/{{ line_item.name }}/{gsub ("^\\s*", "", $NF); print $NF}' {{ __sap_preconfigure_etc_sysctl_sap_conf }}
  register: __sap_preconfigure_register_sysctl_sap_conf_kernel_parameter_assert
  changed_when: no
  ignore_errors: yes
  when: __sap_preconfigure_register_stat_sysctl_sap_conf_assert.stat.exists

- name: Assert that {{ line_item.name }} is set correctly in {{ __sap_preconfigure_etc_sysctl_sap_conf }}
  assert:
    that: "__sap_preconfigure_register_sysctl_sap_conf_kernel_parameter_assert.stdout == '{{ line_item.value }}'"
    fail_msg: "FAIL: The value of '{{ line_item.name }}' in '{{ __sap_preconfigure_etc_sysctl_sap_conf }}' is
               '{{ __sap_preconfigure_register_sysctl_sap_conf_kernel_parameter_assert.stdout }}' but the expected value is '{{ line_item.value }}'!"
    success_msg: "PASS: The value of '{{ line_item.name }}' in '{{ __sap_preconfigure_etc_sysctl_sap_conf }}' is
                  '{{ __sap_preconfigure_register_sysctl_sap_conf_kernel_parameter_assert.stdout }}'."
  ignore_errors: "{{ sap_preconfigure_assert_ignore_errors|d(false) }}"
  when: __sap_preconfigure_register_stat_sysctl_sap_conf_assert.stat.exists

- name: Get {{ line_item.name }} from sysctl
  shell: sysctl -n {{ line_item.name }} | awk '{gsub ("\t", " "); print}'
  register: __sap_preconfigure_register_sysctl_kernel_parameter_assert
  changed_when: no
  ignore_errors: yes

- name: Assert that {{ line_item.name }} is set correctly as per sysctl
  assert:
    that: "__sap_preconfigure_register_sysctl_kernel_parameter_assert.stdout == '{{ line_item.value }}'"
    fail_msg: "FAIL: The current value of '{{ line_item.name }}' as per sysctl is
               '{{ __sap_preconfigure_register_sysctl_kernel_parameter_assert.stdout }}' but the expected value is '{{ line_item.value }}'!"
    success_msg: "PASS: The current value of '{{ line_item.name }}' as per sysctl is
                  '{{ __sap_preconfigure_register_sysctl_kernel_parameter_assert.stdout }}'."
  ignore_errors: "{{ sap_preconfigure_assert_ignore_errors|d(false) }}"
