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.

66 line
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. {%- if 'ipaddr' in n -%}
  16. {%- set state_id = 'network_' ~ n.name ~ '_' ~ n.ipaddr -%}
  17. {%- else %}
  18. {%- set state_id = 'network_' ~ n.name -%}
  19. {%- endif %}
  20. {{ state_id }}:
  21. network:
  22. - managed
  23. - name: {{ n.name }}
  24. - enabled: {{ n.enabled|default(datamap.interfaces.default_values.enabled) }}
  25. - type: {{ n.type|default(datamap.interfaces.default_values.type) }}
  26. {% for p in datamap.interfaces.params_supported %}
  27. {{ set_p(p, n) }}
  28. {% endfor %}
  29. {% if n.use is defined %}
  30. - use:
  31. {% for u in n.use %}
  32. - network: network_{{ u }}
  33. {% endfor %}
  34. {% endif %}
  35. {% if n.provider is defined %}
  36. - provider: {{ n.provider }}
  37. {% endif %}
  38. {% if n.user is defined %}
  39. - user: {{ n.user }}
  40. {% endif %}
  41. {% if n.password is defined %}
  42. - password: {{ n.password }}
  43. {% endif %}
  44. {% if n.pppoe_iface is defined %}
  45. - pppoe_iface: {{ n.pppoe_iface }}
  46. {% endif %}
  47. {% if n.type|default(datamap.interfaces.default_values.type) == 'vlan' and datamap.interfaces.vlan_pkg|default('vlan') %}
  48. {% do pkgs.append(datamap.interfaces.vlan_pkg|default('vlan')) %}
  49. - require:
  50. - pkg: packages
  51. {% endif %}
  52. {% endfor %}
  53. {% if pkgs|length > 0 %}
  54. packages:
  55. pkg:
  56. - installed
  57. - pkgs: {{ pkgs }}
  58. {% endif %}