interfaces.tmpl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. {#- Configure stuff for bonding, bridging, etc.? #}
  47. {%- for feature in ['batman', 'bond', 'bridge', 'vlan', 'vxlan'] if feature in config %}
  48. {%- set feature_config = config.get (feature) %}
  49. {%- for opt in feature_config|sort %}
  50. {{ opt }} {{ feature_config.get (opt) }}
  51. {%- endfor %}
  52. #
  53. {%- endfor %}
  54. {#- Configure IP addresses #}
  55. {%- for prefix in config.get ('prefixes', []) %}
  56. address {{ prefix }}
  57. {%- endfor %}
  58. {#- Anything else... #}
  59. {%- for keyword in config|sort %}
  60. {%- set argument = config.get (keyword) %}
  61. {%- if argument is none %}
  62. {%- elif keyword.startswith ("_") %}
  63. {%- elif keyword in [ 'auto', 'batman', 'bond', 'bridge', 'method', 'vlan', 'vxlan', 'desc', 'prefixes' ] %}
  64. {%- elif argument is string or argument is number %}
  65. {{ keyword }} {{ argument }}
  66. {%- else %}
  67. {%- for item in argument %}
  68. {{ keyword }} {{ item }}
  69. {%- endfor %}
  70. {%- endif %}
  71. {%- endfor %}
  72. {% endfor %}
  73. {#-
  74. # OpenVPN VPNs (if any)
  75. #}
  76. {%- include "network/interfaces/openvpn.tmpl" %}
  77. {#-
  78. # Tinc VPNs (if any)
  79. #}
  80. {#%- include "network/interfaces/tinc.tmpl" %#}