interfaces.tmpl 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 on loopback, if present
  11. #}
  12. # The loopback network interface
  13. auto lo
  14. iface lo
  15. {%- if 'lo' in ifaces %}
  16. {%- for prefix in ifaces['lo']['prefixes'] %}
  17. {%- set mask = '128' if ':' in prefix else '32' %}
  18. {%- set prefix = prefix if '/' in prefix else prefix ~ '/' ~ mask %}
  19. address {{ prefix }}
  20. {%- endfor %}
  21. {%- endif %}
  22. {#
  23. # Set up ifaces dict with configured and generated interfaces.
  24. #}
  25. {%- for interface in ifaces|sort if interface not in ['lo'] %}
  26. {%- set config = ifaces.get (interface) %}
  27. {#- Let's go #}
  28. {%- set planned = "" %}
  29. {%- if config.get ('status', 'online') == 'planned' %}
  30. {%- set planned = " (Planned)" %}
  31. {%- endif %}
  32. {%- set desc = config.get ('desc', interface) %}
  33. {%- set alias = config.get ('alias', desc) + planned %}
  34. # {{ desc + planned }}
  35. {%- if config.get ('auto', True) == True %}
  36. auto {{ interface }}
  37. {%- endif %}
  38. {%- if 'method' in config %}
  39. iface {{ interface }} inet {{ config.get ('method') }}
  40. {%- else %}
  41. iface {{ interface }}
  42. {%- endif %}
  43. {#- Alias / Description set? #}
  44. {%- if 'alias' in config or 'desc' in config %}
  45. alias "{{ alias }}"
  46. #
  47. {%- endif %}
  48. {#- Configure stuff for bonding, bridging, etc.? #}
  49. {%- for feature in ['batman', 'bond', 'bridge', 'vlan', 'vxlan'] if feature in config %}
  50. {%- set feature_config = config.get (feature) %}
  51. {%- for opt in feature_config|sort %}
  52. {{ opt }} {{ feature_config.get (opt) }}
  53. {%- endfor %}
  54. #
  55. {%- endfor %}
  56. {#- Configure IP addresses #}
  57. {%- for prefix in config.get ('prefixes', []) %}
  58. address {{ prefix }}
  59. {%- endfor %}
  60. {#- Anything else... #}
  61. {%- for keyword in config|sort %}
  62. {%- set argument = config.get (keyword) %}
  63. {%- if argument is none %}
  64. {%- elif keyword.startswith ("_") %}
  65. {%- elif keyword in [ 'auto', 'batman', 'bond', 'bridge', 'mac', 'method', 'vlan', 'vxlan', 'desc', 'prefixes', 'status', 'tagged_vlans', 'has_gateway' ] %}
  66. {%- elif argument is string or argument is number %}
  67. {{ keyword }} {{ argument }}
  68. {%- else %}
  69. {%- for item in argument %}
  70. {{ keyword }} {{ item }}
  71. {%- endfor %}
  72. {%- endif %}
  73. {%- endfor %}
  74. {% endfor %}
  75. {#-
  76. # OpenVPN VPNs (if any)
  77. #}
  78. {%- include "network/interfaces/openvpn.tmpl" %}