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

61 行
1.8KB

  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.password is defined %}
  38. - password: {{ n.password }}
  39. {% endif %}
  40. {% if n.pppoe_iface is defined %}
  41. - pppoe_iface: {{ n.pppoe_iface }}
  42. {% endif %}
  43. {% if n.type|default(datamap.interfaces.default_values.type) == 'vlan' and datamap.interfaces.vlan_pkg|default('vlan') %}
  44. {% do pkgs.append(datamap.interfaces.vlan_pkg|default('vlan')) %}
  45. - require:
  46. - pkg: packages
  47. {% endif %}
  48. {% endfor %}
  49. {% if pkgs|length > 0 %}
  50. packages:
  51. pkg:
  52. - installed
  53. - pkgs: {{ pkgs }}
  54. {% endif %}