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

58 行
1.7KB

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