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.7KB

10 jaren geleden
10 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.provider is defined %}
  32. - provider: {{ n.provider }}
  33. {% endif %}
  34. {% if n.user is defined %}
  35. - user: {{ n.user }}
  36. {% endif %}
  37. {% if n.pass is defined %}
  38. - pass: {{ n.pass }}
  39. {% endif %}
  40. {% if n.type|default(datamap.interfaces.default_values.type) == 'vlan' and datamap.interfaces.vlan_pkg|default('vlan') %}
  41. {% do pkgs.append(datamap.interfaces.vlan_pkg|default('vlan')) %}
  42. - require:
  43. - pkg: packages
  44. {% endif %}
  45. {% endfor %}
  46. {% if pkgs|length > 0 %}
  47. packages:
  48. pkg:
  49. - installed
  50. - pkgs: {{ pkgs }}
  51. {% endif %}