Bechtoldt's Network Saltstack Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

49 行
1.4KB

  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 %}