Saltstack Official Linux Formula
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

219 rindas
6.1KB

  1. {%- from "linux/map.jinja" import network with context %}
  2. {%- from "linux/map.jinja" import system with context %}
  3. {%- if network.enabled %}
  4. {%- macro set_param(param_name, param_dict) -%}
  5. {%- if param_dict.get(param_name, False) -%}
  6. - {{ param_name }}: {{ param_dict[param_name] }}
  7. {%- endif -%}
  8. {%- endmacro -%}
  9. {%- if network.bridge != 'none' %}
  10. linux_network_bridge_pkgs:
  11. pkg.installed:
  12. {%- if network.bridge == 'openvswitch' %}
  13. - names: {{ network.ovs_pkgs }}
  14. {%- else %}
  15. - names: {{ network.bridge_pkgs }}
  16. {%- endif %}
  17. {%- endif %}
  18. {%- for interface_name, interface in network.interface.iteritems() %}
  19. {%- if interface.get('managed', True) %}
  20. {%- if grains.os_family in ['RedHat', 'Debian'] %}
  21. {%- if interface.type == 'bridge' and network.bridge == 'openvswitch' %}
  22. linux_interface_{{ interface_name }}:
  23. network.managed:
  24. - enabled: {{ interface.enabled }}
  25. - name: {{ interface_name }}
  26. - type: eth
  27. {%- if interface.address is defined %}
  28. - proto: {{ interface.get('proto', 'static') }}
  29. - ipaddr: {{ interface.address }}
  30. - netmask: {{ interface.netmask }}
  31. {%- else %}
  32. - proto: {{ interface.get('proto', 'dhcp') }}
  33. {%- endif %}
  34. {%- if interface.name_servers is defined %}
  35. - dns: {{ interface.name_servers }}
  36. {%- endif %}
  37. {%- for param in network.interface_params %}
  38. {{ set_param(param, interface) }}
  39. {%- endfor %}
  40. {%- if interface.wireless is defined and grains.os_family == 'Debian' %}
  41. {%- if interface.wireless.security == "wpa" %}
  42. - wpa-ssid: {{ interface.wireless.essid }}
  43. - wpa-psk: {{ interface.wireless.key }}
  44. {%- else %}
  45. - wireless-ssid: {{ interface.wireless.essid }}
  46. - wireless-psk: {{ interface.wireless.key }}
  47. {%- endif %}
  48. {%- endif %}
  49. - require:
  50. - pkg: linux_network_bridge_pkgs
  51. {%- for network in interface.use_interfaces %}
  52. - network: linux_interface_{{ network }}
  53. {%- endfor %}
  54. linux_ovs_bridge_{{ interface_name }}:
  55. cmd.run:
  56. - name: ovs-vsctl add-br {{ interface_name }}
  57. - unless: ovs-vsctl show | grep 'Bridge {{ interface_name }}'
  58. - require:
  59. - network: linux_interface_{{ interface_name }}
  60. {%- for port in interface.use_interfaces %}
  61. linux_ovs_bridge_{{ interface_name }}_port_{{ port }}:
  62. cmd.run:
  63. - name: ovs-vsctl add-port {{ interface_name }} {{ port }}
  64. - unless: ovs-vsctl show | grep 'Interface "{{ interface_name }}"'
  65. - require:
  66. - cmd: linux_ovs_bridge_{{ interface_name }}
  67. {%- endfor %}
  68. {%- else %}
  69. linux_interface_{{ interface_name }}:
  70. network.managed:
  71. - enabled: {{ interface.enabled }}
  72. - name: {{ interface_name }}
  73. - type: {{ interface.type }}
  74. {%- if interface.address is defined %}
  75. {%- if grains.os_family == 'Debian' %}
  76. - proto: {{ interface.get('proto', 'static') }}
  77. {% endif %}
  78. {%- if grains.os_family == 'RedHat' %}
  79. - proto: {{ interface.get('proto', 'none') }}
  80. {% endif %}
  81. - ipaddr: {{ interface.address }}
  82. - netmask: {{ interface.netmask }}
  83. {%- else %}
  84. - proto: {{ interface.get('proto', 'dhcp') }}
  85. {%- endif %}
  86. {%- if interface.name_servers is defined %}
  87. - dns: {{ interface.name_servers }}
  88. {%- endif %}
  89. {%- if interface.wireless is defined and grains.os_family == 'Debian' %}
  90. {%- if interface.wireless.security == "wpa" %}
  91. - wpa-ssid: {{ interface.wireless.essid }}
  92. - wpa-psk: {{ interface.wireless.key }}
  93. {%- else %}
  94. - wireless-ssid: {{ interface.wireless.essid }}
  95. - wireless-psk: {{ interface.wireless.key }}
  96. {%- endif %}
  97. {%- endif %}
  98. {%- for param in network.interface_params %}
  99. {{ set_param(param, interface) }}
  100. {%- endfor %}
  101. {%- if interface.type == 'bridge' %}
  102. - bridge: {{ interface_name }}
  103. - delay: 0
  104. - bypassfirewall: True
  105. - use:
  106. {%- for network in interface.use_interfaces %}
  107. - network: linux_interface_{{ network }}
  108. {%- endfor %}
  109. - ports: {% for network in interface.use_interfaces %}{{ network }} {% endfor %}
  110. - require:
  111. {%- for network in interface.use_interfaces %}
  112. - network: linux_interface_{{ network }}
  113. {%- endfor %}
  114. {%- endif %}
  115. {%- if interface.type == 'bond' %}
  116. - slaves: {{ interface.slaves }}
  117. - mode: {{ interface.mode }}
  118. {%- endif %}
  119. {%- if interface.gateway is defined %}
  120. linux_system_network:
  121. network.system:
  122. - enabled: {{ interface.enabled }}
  123. - hostname: {{ network.fqdn }}
  124. {%- if interface.gateway is defined %}
  125. - gateway: {{ interface.gateway }}
  126. - gatewaydev: {{ interface_name }}
  127. {%- endif %}
  128. - nozeroconf: True
  129. - nisdomain: {{ system.domain }}
  130. - require_reboot: False
  131. {%- endif %}
  132. {%- endif %}
  133. {%- endif %}
  134. {%- if interface.wireless is defined %}
  135. {%- if grains.os_family == 'Arch' %}
  136. linux_network_packages:
  137. pkg.installed:
  138. - names: {{ network.pkgs }}
  139. /etc/netctl/network_{{ interface.wireless.essid }}:
  140. file.managed:
  141. - source: salt://linux/files/wireless
  142. - mode: 755
  143. - template: jinja
  144. - require:
  145. - pkg: linux_network_packages
  146. - defaults:
  147. interface_name: {{ interface_name }}
  148. switch_profile_{{ interface.wireless.essid }}:
  149. cmd.run:
  150. - name: netctl switch-to network_{{ interface.wireless.essid }}
  151. - cwd: /root
  152. - unless: "iwconfig {{ interface_name }} | grep -e 'ESSID:\"{{ interface.wireless.essid }}\"'"
  153. - require:
  154. - file: /etc/netctl/network_{{ interface.wireless.essid }}
  155. enable_profile_{{ interface.wireless.essid }}:
  156. cmd.run:
  157. - name: netctl enable network_{{ interface.wireless.essid }}
  158. - cwd: /root
  159. - unless: test -e /etc/systemd/system/multi-user.target.wants/netctl@network_{{ interface.wireless.essid }}.service
  160. - require:
  161. - file: /etc/netctl/network_{{ interface.wireless.essid }}
  162. {%- endif %}
  163. {%- endif %}
  164. {%- endif %}
  165. {%- if interface.route is defined %}
  166. linux_network_{{ interface_name }}_routes:
  167. network.routes:
  168. - name: {{ interface_name }}
  169. - routes:
  170. {%- for route_name, route in interface.route.iteritems() %}
  171. - name: {{ route_name }}
  172. ipaddr: {{ route.address }}
  173. netmask: {{ route.netmask }}
  174. gateway: {{ route.gateway }}
  175. {%- endfor %}
  176. {%- endif %}
  177. {%- endfor %}
  178. {%- endif %}
  179. {%- if network.network_manager.disable is defined and network.network_manager.disable == True %}
  180. NetworkManager:
  181. service.dead:
  182. - enable: false
  183. {%- endif %}