interfaces.tmpl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #source /etc/network/interfaces.d/*
  8. {#
  9. # Configure any secondary IPs / router_id / infra-srv IPs on loopback, if present
  10. #}
  11. {%- set lo_prefixes = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces:lo:prefixes', []) %}
  12. {#- Add user/infra-srv VPN IPs, too #}
  13. {%- for vpn in ['user-srv', 'infra-srv'] %}
  14. {#- COMPATIBILITY GLUE #}
  15. {%- for prefix in salt['pillar.get']("tinc:" ~ vpn ~ ":" ~ grains['nodename'] ~ ":subnet", []) %}
  16. {%- do lo_prefixes.append (prefix) %}
  17. {%- endfor %}
  18. {%- for prefix in salt['pillar.get']("tinc:" ~ vpn ~ ":" ~ grains['id'] ~ ":subnet", []) %}
  19. {%- do lo_prefixes.append (prefix) %}
  20. {%- endfor %}
  21. {%- endfor %}
  22. # The loopback network interface
  23. auto lo
  24. iface lo
  25. {%- for prefix in lo_prefixes %}
  26. {%- set mask = '128' if ':' in prefix else '32' %}
  27. {%- set prefix = prefix if '/' in prefix else prefix ~ '/' ~ mask %}
  28. address {{ prefix }}
  29. {%- endfor %}
  30. {#
  31. # Special static config for this node?
  32. {%- set host_config_file = "network/interfaces/hosts/" ~ node_id ~ ".cfg" %}
  33. {%- include host_config_file ignore missing %}
  34. #}
  35. {#
  36. # Set up ifaces dict with configured and generated interfaces.
  37. #}
  38. {%- set ifaces = salt['ffho_net.get_interface_config'](node_config, sites_config) %}
  39. {%- for interface in ifaces|sort if interface not in ['lo'] %}
  40. {%- set config = ifaces.get (interface) %}
  41. {#- Let's go #}
  42. # {{ config.get ('desc', interface) }}
  43. {%- if config.get ('auto', True) == True %}
  44. auto {{ interface }}
  45. {%- endif %}
  46. {%- if 'method' in config %}
  47. iface {{ interface }} inet {{ config.get ('method') }}
  48. {%- else %}
  49. iface {{ interface }}
  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" %#}