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.

82 line
2.3KB

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