interfaces.tmpl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #source /etc/network/interfaces.d/*
  9. {#
  10. # Configure any secondary IPs / router_id / infra-srv IPs on loopback, if present
  11. #}
  12. {%- set lo_prefixes = ifaces['lo']['prefixes'] %}
  13. {#- Add user/infra-srv VPN IPs, too #}
  14. {%- for vpn in ['user-srv', 'infra-srv'] %}
  15. {#- COMPATIBILITY GLUE #}
  16. {%- for prefix in salt['pillar.get']("tinc:" ~ vpn ~ ":" ~ grains['nodename'] ~ ":subnet", []) %}
  17. {%- do lo_prefixes.append (prefix) %}
  18. {%- endfor %}
  19. {%- for prefix in salt['pillar.get']("tinc:" ~ vpn ~ ":" ~ grains['id'] ~ ":subnet", []) %}
  20. {%- do lo_prefixes.append (prefix) %}
  21. {%- endfor %}
  22. {%- endfor %}
  23. # The loopback network interface
  24. auto lo
  25. iface lo
  26. {%- for prefix in lo_prefixes %}
  27. {%- set mask = '128' if ':' in prefix else '32' %}
  28. {%- set prefix = prefix if '/' in prefix else prefix ~ '/' ~ mask %}
  29. address {{ prefix }}
  30. {%- endfor %}
  31. {#
  32. # Set up ifaces dict with configured and generated interfaces.
  33. #}
  34. {%- for interface in ifaces|sort if interface not in ['lo'] %}
  35. {%- set config = ifaces.get (interface) %}
  36. {#- Let's go #}
  37. # {{ config.get ('desc', interface) }}
  38. {%- if config.get ('auto', True) == True %}
  39. auto {{ interface }}
  40. {%- endif %}
  41. {%- if 'method' in config %}
  42. iface {{ interface }} inet {{ config.get ('method') }}
  43. {%- else %}
  44. iface {{ interface }}
  45. {%- endif %}
  46. {#- Alias / Description set? #}
  47. {%- if 'alias' in config or 'desc' in config %}
  48. alias "{{ config.get ('alias', config.get ('desc')) }}"
  49. #
  50. {%- endif %}
  51. {#- Configure stuff for bonding, bridging, etc.? #}
  52. {%- for feature in ['batman', 'bond', 'bridge', 'vlan', 'vxlan'] if feature in config %}
  53. {%- set feature_config = config.get (feature) %}
  54. {%- for opt in feature_config|sort %}
  55. {{ opt }} {{ feature_config.get (opt) }}
  56. {%- endfor %}
  57. #
  58. {%- endfor %}
  59. {#- Configure IP addresses #}
  60. {%- for prefix in config.get ('prefixes', []) %}
  61. address {{ prefix }}
  62. {%- endfor %}
  63. {#- Anything else... #}
  64. {%- for keyword in config|sort %}
  65. {%- set argument = config.get (keyword) %}
  66. {%- if argument is none %}
  67. {%- elif keyword.startswith ("_") %}
  68. {%- elif keyword in [ 'auto', 'batman', 'bond', 'bridge', 'method', 'vlan', 'vxlan', 'desc', 'prefixes' ] %}
  69. {%- elif argument is string or argument is number %}
  70. {{ keyword }} {{ argument }}
  71. {%- else %}
  72. {%- for item in argument %}
  73. {{ keyword }} {{ item }}
  74. {%- endfor %}
  75. {%- endif %}
  76. {%- endfor %}
  77. {% endfor %}
  78. {#-
  79. # OpenVPN VPNs (if any)
  80. #}
  81. {%- include "network/interfaces/openvpn.tmpl" %}
  82. {#-
  83. # Tinc VPNs (if any)
  84. #}
  85. {#%- include "network/interfaces/tinc.tmpl" %#}