interfaces.tmpl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #
  2. # /etc/network/interfaces (Salt managed)
  3. #
  4. {%- set node_config = salt['pillar.get']('nodes:' ~ grains['id'], {}) %}
  5. {%- set node_id = grains['id'] %}
  6. {%- set sites_config = salt['pillar.get']('sites', {}) %}
  7. {%- set ifaces = salt['ffho_net.get_interface_config'](node_config, sites_config) %}
  8. {%- set iface_list = salt['ffho_net.get_interface_list'](ifaces) %}
  9. #source /etc/network/interfaces.d/*
  10. {#
  11. # Configure any secondary IPs / router_id on loopback, if present
  12. #}
  13. # The loopback network interface
  14. auto lo
  15. iface lo
  16. {%- if 'lo' in ifaces %}
  17. {%- for prefix in ifaces['lo']['prefixes'] %}
  18. {%- set mask = '128' if ':' in prefix else '32' %}
  19. {%- set prefix = prefix if '/' in prefix else prefix ~ '/' ~ mask %}
  20. address {{ prefix }}
  21. {%- endfor %}
  22. {%- endif %}
  23. {#
  24. # Set up ifaces dict with configured and generated interfaces.
  25. #}
  26. {%- for interface in iface_list if interface not in ['lo'] %}
  27. {%- set config = ifaces.get (interface) %}
  28. {#- Let's go #}
  29. {%- set planned = "" %}
  30. {%- if config.get ('status', 'online') == 'planned' %}
  31. {%- set planned = " (Planned)" %}
  32. {%- endif %}
  33. {%- set desc = config.get ('desc', interface) %}
  34. {%- set alias = config.get ('alias', desc) + planned %}
  35. # {{ desc + planned }}
  36. {%- if config.get ('auto', True) == True %}
  37. auto {{ interface }}
  38. {%- endif %}
  39. {%- if 'method' in config %}
  40. iface {{ interface }} inet {{ config.get ('method') }}
  41. {%- else %}
  42. iface {{ interface }}
  43. {%- endif %}
  44. {#- Alias / Description set? #}
  45. {%- if 'alias' in config or 'desc' in config %}
  46. alias "{{ alias }}"
  47. #
  48. {%- endif %}
  49. {#- Configure stuff for bonding, bridging, etc.? #}
  50. {%- for feature in ['batman', 'bond', 'bridge', 'vlan', 'vxlan'] if feature in config %}
  51. {%- set feature_config = config.get (feature) %}
  52. {%- for opt in feature_config|sort %}
  53. {{ opt }} {{ feature_config.get (opt) }}
  54. {%- endfor %}
  55. #
  56. {%- endfor %}
  57. {#- Wireguard tunnel? #}
  58. {%- if 'wireguard' in config %}
  59. use wireguard
  60. up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/addr_gen_mode
  61. #
  62. {%- endif %}
  63. {#- Configure IP addresses #}
  64. {%- for prefix in config.get ('prefixes', []) %}
  65. address {{ prefix }}
  66. {%- endfor %}
  67. {#- Anything else... #}
  68. {%- for keyword in config|sort %}
  69. {%- set argument = config.get (keyword) %}
  70. {%- if argument is none %}
  71. {%- elif keyword.startswith ("_") %}
  72. {%- elif keyword in [ 'auto', 'batman', 'bond', 'bridge', 'driver', 'mac', 'method', 'vlan', 'vxlan', 'desc', 'prefixes', 'status', 'tagged_vlans', 'tags', 'urpf', 'has_gateway', 'wireguard' ] %}
  73. {%- elif argument is string or argument is number %}
  74. {{ keyword }} {{ argument }}
  75. {%- else %}
  76. {%- for item in argument %}
  77. {{ keyword }} {{ item }}
  78. {%- endfor %}
  79. {%- endif %}
  80. {%- endfor %}
  81. {% endfor %}
  82. {#-
  83. # OpenVPN VPNs (if any)
  84. #}
  85. {%- include "network/interfaces/openvpn.tmpl" %}