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.

76 line
2.1KB

  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 'dhclient_conf' in salt['pillar.get']('network') %}
  12. dhclient_conf:
  13. file.managed:
  14. - name: /etc/dhcp/dhclient.conf
  15. - mode: 644
  16. - user: root
  17. - group: root
  18. - contents_pillar: network:dhclient_conf
  19. {% endif %}
  20. {%- if salt['pillar.get']('network:interfaces', False) %}
  21. {% set interfaces = interfaces + salt['pillar.get']('network:interfaces') %}
  22. {% endif %}
  23. {% for n in interfaces -%}
  24. {%- if 'ipaddr' in n -%}
  25. {%- set state_id = 'network_' ~ n.name ~ '_' ~ n.ipaddr -%}
  26. {%- else %}
  27. {%- set state_id = 'network_' ~ n.name -%}
  28. {%- endif %}
  29. {{ state_id }}:
  30. network:
  31. - managed
  32. - name: {{ n.name }}
  33. - enabled: {{ n.enabled|default(datamap.interfaces.default_values.enabled) }}
  34. - type: {{ n.type|default(datamap.interfaces.default_values.type) }}
  35. {% for p in datamap.interfaces.params_supported %}
  36. {{ set_p(p, n) }}
  37. {% endfor %}
  38. {% if n.use is defined %}
  39. - use:
  40. {% for u in n.use %}
  41. - network: network_{{ u }}
  42. {% endfor %}
  43. {% endif %}
  44. {% if n.provider is defined %}
  45. - provider: {{ n.provider }}
  46. {% endif %}
  47. {% if n.user is defined %}
  48. - user: {{ n.user }}
  49. {% endif %}
  50. {% if n.password is defined %}
  51. - password: {{ n.password }}
  52. {% endif %}
  53. {% if n.pppoe_iface is defined %}
  54. - pppoe_iface: {{ n.pppoe_iface }}
  55. {% endif %}
  56. {% if n.type|default(datamap.interfaces.default_values.type) == 'vlan' and datamap.interfaces.vlan_pkg|default('vlan') %}
  57. {% do pkgs.append(datamap.interfaces.vlan_pkg|default('vlan')) %}
  58. - require:
  59. - pkg: packages
  60. {% endif %}
  61. {% endfor %}
  62. {% if pkgs|length > 0 %}
  63. packages:
  64. pkg:
  65. - installed
  66. - pkgs: {{ pkgs }}
  67. {% endif %}