Saltstack Official Linux Formula
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

223 lines
6.2KB

  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. {%- if interface.get('proto', 'none') == 'manual' %}
  80. - proto: 'none'
  81. {%- else %}
  82. - proto: {{ interface.get('proto', 'none') }}
  83. {%- endif %}
  84. {% endif %}
  85. - ipaddr: {{ interface.address }}
  86. - netmask: {{ interface.netmask }}
  87. {%- else %}
  88. - proto: {{ interface.get('proto', 'dhcp') }}
  89. {%- endif %}
  90. {%- if interface.name_servers is defined %}
  91. - dns: {{ interface.name_servers }}
  92. {%- endif %}
  93. {%- if interface.wireless is defined and grains.os_family == 'Debian' %}
  94. {%- if interface.wireless.security == "wpa" %}
  95. - wpa-ssid: {{ interface.wireless.essid }}
  96. - wpa-psk: {{ interface.wireless.key }}
  97. {%- else %}
  98. - wireless-ssid: {{ interface.wireless.essid }}
  99. - wireless-psk: {{ interface.wireless.key }}
  100. {%- endif %}
  101. {%- endif %}
  102. {%- for param in network.interface_params %}
  103. {{ set_param(param, interface) }}
  104. {%- endfor %}
  105. {%- if interface.type == 'bridge' %}
  106. - bridge: {{ interface_name }}
  107. - delay: 0
  108. - bypassfirewall: True
  109. - use:
  110. {%- for network in interface.use_interfaces %}
  111. - network: linux_interface_{{ network }}
  112. {%- endfor %}
  113. - ports: {% for network in interface.use_interfaces %}{{ network }} {% endfor %}
  114. - require:
  115. {%- for network in interface.use_interfaces %}
  116. - network: linux_interface_{{ network }}
  117. {%- endfor %}
  118. {%- endif %}
  119. {%- if interface.type == 'bond' %}
  120. - slaves: {{ interface.slaves }}
  121. - mode: {{ interface.mode }}
  122. {%- endif %}
  123. {%- if interface.gateway is defined %}
  124. linux_system_network:
  125. network.system:
  126. - enabled: {{ interface.enabled }}
  127. - hostname: {{ network.fqdn }}
  128. {%- if interface.gateway is defined %}
  129. - gateway: {{ interface.gateway }}
  130. - gatewaydev: {{ interface_name }}
  131. {%- endif %}
  132. - nozeroconf: True
  133. - nisdomain: {{ system.domain }}
  134. - require_reboot: False
  135. {%- endif %}
  136. {%- endif %}
  137. {%- endif %}
  138. {%- if interface.wireless is defined %}
  139. {%- if grains.os_family == 'Arch' %}
  140. linux_network_packages:
  141. pkg.installed:
  142. - names: {{ network.pkgs }}
  143. /etc/netctl/network_{{ interface.wireless.essid }}:
  144. file.managed:
  145. - source: salt://linux/files/wireless
  146. - mode: 755
  147. - template: jinja
  148. - require:
  149. - pkg: linux_network_packages
  150. - defaults:
  151. interface_name: {{ interface_name }}
  152. switch_profile_{{ interface.wireless.essid }}:
  153. cmd.run:
  154. - name: netctl switch-to network_{{ interface.wireless.essid }}
  155. - cwd: /root
  156. - unless: "iwconfig {{ interface_name }} | grep -e 'ESSID:\"{{ interface.wireless.essid }}\"'"
  157. - require:
  158. - file: /etc/netctl/network_{{ interface.wireless.essid }}
  159. enable_profile_{{ interface.wireless.essid }}:
  160. cmd.run:
  161. - name: netctl enable network_{{ interface.wireless.essid }}
  162. - cwd: /root
  163. - unless: test -e /etc/systemd/system/multi-user.target.wants/netctl@network_{{ interface.wireless.essid }}.service
  164. - require:
  165. - file: /etc/netctl/network_{{ interface.wireless.essid }}
  166. {%- endif %}
  167. {%- endif %}
  168. {%- endif %}
  169. {%- if interface.route is defined %}
  170. linux_network_{{ interface_name }}_routes:
  171. network.routes:
  172. - name: {{ interface_name }}
  173. - routes:
  174. {%- for route_name, route in interface.route.iteritems() %}
  175. - name: {{ route_name }}
  176. ipaddr: {{ route.address }}
  177. netmask: {{ route.netmask }}
  178. gateway: {{ route.gateway }}
  179. {%- endfor %}
  180. {%- endif %}
  181. {%- endfor %}
  182. {%- endif %}
  183. {%- if network.network_manager.disable is defined and network.network_manager.disable == True %}
  184. NetworkManager:
  185. service.dead:
  186. - enable: false
  187. {%- endif %}