interfaces.tmpl 3.0 KB

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