interfaces.tmpl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. {%- set planned = "" %}
  28. {%- if config.get ('status', 'online') == 'planned' %}
  29. {%- set planned = " (Planned)" %}
  30. {%- endif %}
  31. {%- set desc = config.get ('desc', interface) %}
  32. {%- set alias = config.get ('alias', desc) + planned %}
  33. # {{ desc + planned }}
  34. {%- if config.get ('auto', True) == True %}
  35. auto {{ interface }}
  36. {%- endif %}
  37. {%- if 'method' in config %}
  38. iface {{ interface }} inet {{ config.get ('method') }}
  39. {%- else %}
  40. iface {{ interface }}
  41. {%- endif %}
  42. {#- Alias / Description set? #}
  43. {%- if 'alias' in config or 'desc' in config %}
  44. alias "{{ alias }}"
  45. #
  46. {%- endif %}
  47. {#- Configure stuff for bonding, bridging, etc.? #}
  48. {%- for feature in ['batman', 'bond', 'bridge', 'vlan', 'vxlan'] if feature in config %}
  49. {%- set feature_config = config.get (feature) %}
  50. {%- for opt in feature_config|sort %}
  51. {{ opt }} {{ feature_config.get (opt) }}
  52. {%- endfor %}
  53. #
  54. {%- endfor %}
  55. {#- Configure IP addresses #}
  56. {%- for prefix in config.get ('prefixes', []) %}
  57. address {{ prefix }}
  58. {%- endfor %}
  59. {#- Anything else... #}
  60. {%- for keyword in config|sort %}
  61. {%- set argument = config.get (keyword) %}
  62. {%- if argument is none %}
  63. {%- elif keyword.startswith ("_") %}
  64. {%- elif keyword in [ 'auto', 'batman', 'bond', 'bridge', 'method', 'vlan', 'vxlan', 'desc', 'prefixes', 'status', 'tagged_vlans', 'has_gateway' ] %}
  65. {%- elif argument is string or argument is number %}
  66. {{ keyword }} {{ argument }}
  67. {%- else %}
  68. {%- for item in argument %}
  69. {{ keyword }} {{ item }}
  70. {%- endfor %}
  71. {%- endif %}
  72. {%- endfor %}
  73. {% endfor %}
  74. {#-
  75. # OpenVPN VPNs (if any)
  76. #}
  77. {%- include "network/interfaces/openvpn.tmpl" %}