interfaces.tmpl 2.3 KB

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