interfaces.tmpl 2.6 KB

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