{% set ifupdown__tpl_sysctl__dependent_parameters = [] %}
{% if ifupdown__combined_interfaces %}
{%   for interface, params in ifupdown__combined_interfaces.items() %}
{%     set interface_name = (params.iface | d(interface)) %}
{%     if params.state|d('present') in [ 'present', 'absent' ] %}
{%       set ifupdown__tpl_forwarding_parameters = [] %}
{%       if params.forward is defined %}
{%         set _ = ifupdown__tpl_forwarding_parameters.append({
  "name": ("net.ipv6.conf." + interface_name + ".forwarding"),
  "value": (params.forward_ipv6 | d(params.forward)) | bool,
  "comment": ((params.forward_ipv6 | d(params.forward)) | ternary("Enable", "Disable") + " IPv6 forwarding on the " + interface_name + " interface"),
  "state": "present"
}) %}
{%         if params.accept_ra|d() %}
{%           set ra_preference_comment = {
  0: ("Do not accept SLAAC Router Advertisements on the " + interface_name + " interface"),
  1: ("Accept SLAAC Router Advertisements on the " + interface_name + " interface when forwarding is disabled"),
  2: ("Accept SLAAC Router Advertisements on the " + interface_name + " interface even if forwarding is enabled")
} %}
{%           set _ = ifupdown__tpl_forwarding_parameters.append({
  "name": ("net.ipv6.conf." + interface_name + ".accept_ra"),
  "value": params.accept_ra,
  "comment": ra_preference_comment[params.accept_ra|int],
  "state": "present"
}) %}
{%         endif %}
{%         set _ = ifupdown__tpl_forwarding_parameters.append({
  "name": ("net.ipv4.conf." + interface_name + ".forwarding"),
  "value": (params.forward_ipv4 | d(params.forward)) | bool,
  "comment": ((params.forward_ipv4 | d(params.forward)) | ternary("Enable", "Disable") + " IPv4 forwarding on the " + interface_name + " interface"),
  "state": "present"
}) %}
{%       endif %}
{%       set ifupdown__tpl_sysctl_config = {
  "name": ("ifupdown_" + interface_name + "_forwarding"),
  "weight": 50,
  "comment":"Configuration generated by the 'debops.ifupdown' Ansible role",
  "state": ("present" if (params.state|d('present') == 'present' and ifupdown__tpl_forwarding_parameters) else "absent"),
  "options": ifupdown__tpl_forwarding_parameters
} %}
{%       set _ = ifupdown__tpl_sysctl__dependent_parameters.append(ifupdown__tpl_sysctl_config) %}
{%     endif %}
{%   endfor %}
{% endif %}
{{ ifupdown__tpl_sysctl__dependent_parameters | to_yaml }}
