Bechtoldt's Network Saltstack Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

interfaces.sls 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!jinja|yaml
  2. {% from "network/defaults.yaml" import rawmap with context %}
  3. {% set datamap = salt['grains.filter_by'](rawmap, merge=salt['pillar.get']('network:lookup')) %}
  4. {% set interfaces = datamap.interfaces.def_entries %}
  5. {% set pkgs = datamap.interfaces.pkgs|default([]) %}
  6. {%- macro set_p(paramname, dictvar) -%}
  7. {%- if paramname in dictvar -%}
  8. - {{ paramname }}: {{ dictvar[paramname] }}
  9. {%- endif -%}
  10. {%- endmacro -%}
  11. {% if salt['pillar.get']('network:interfaces', False) %}
  12. {% set interfaces = interfaces + salt['pillar.get']('network:interfaces') %}
  13. {% endif %}
  14. {% for n in interfaces %}
  15. network-{{ n.name }}:
  16. network:
  17. - managed
  18. - name: {{ n.name }}
  19. - enabled: {{ n.enable|default(datamap.interfaces.default_values.enable) }}
  20. - proto: {{ n.proto|default(datamap.interfaces.default_values.proto) }}
  21. - type: {{ n.type|default(datamap.interfaces.default_values.type) }}
  22. {% for p in datamap.interfaces.params_supported %}
  23. {{ set_p(p, n) }}
  24. {% endfor %}
  25. {% if n.use is defined %}
  26. - use:
  27. {% for u in n.use %}
  28. - network: network-{{ u }}
  29. {% endfor %}
  30. {% endif %}
  31. {% if n.type|default(datamap.interfaces.default_values.type) == 'vlan' and datamap.interfaces.vlan_pkg|default('vlan') %}
  32. {% do pkgs.append(datamap.interfaces.vlan_pkg|default('vlan')) %}
  33. - require:
  34. - pkg: packages
  35. {% endif %}
  36. {% endfor %}
  37. {% if pkgs|length > 0 %}
  38. packages:
  39. pkg:
  40. - installed
  41. - pkgs: {{ pkgs }}
  42. {% endif %}