{{ ansible_managed | comment }}
{{ "system_role:kernel_settings" | comment(prefix="", postfix="") }}
{% macro write_section(section_name, settings) %}
[{{ section_name }}]
{%   for key, val in settings.items() %}
{%     if val != {"state": "absent"} %}
{{ key }} = {{ val }}
{%     endif %}
{%   endfor %}
{% endmacro %}
[main]
summary = kernel settings
{% if __sysctl_has_values %}
{{   write_section("sysctl", __kernel_settings_new_sysctl) -}}
{% endif %}
{% if __sysfs_has_values %}
{{   write_section("sysfs", __kernel_settings_new_sysfs) -}}
{% endif %}
{% if __systemd_new | length > 0 %}
[systemd]
cpu_affinity = {{ __systemd_new }}
{% endif %}
{% if __trans_huge_new | length > 0 or __trans_defrag_new | length > 0 %}
[vm]
{%   if __trans_huge_new | length > 0 %}
transparent_hugepages = {{ __trans_huge_new }}
{%   endif %}
{%   if __trans_defrag_new | length > 0 %}
transparent_hugepage.defrag = {{ __trans_defrag_new }}
{%   endif %}
{% endif %}
