Saltstack Official Linux Formula
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

253 lines
6.6KB

  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 == 'ovs_bridge' %}
  22. ovs_bridge_{{ interface_name }}:
  23. openvswitch_bridge.present:
  24. - name: {{ interface_name }}
  25. {%- elif interface.type == 'ovs_port' %}
  26. {#
  27. ovs_port_{{ interface_name }}:
  28. openvswitch_port.present:
  29. - name: {{ interface_name }}
  30. - bridge: {{ interface.bridge }}
  31. - require:
  32. - openvswitch_bridge: ovs_bridge_{{ interface.bridge }}
  33. #}
  34. linux_interfaces_include:
  35. file.prepend:
  36. - name: /etc/network/interfaces
  37. - text: 'source /etc/network/interfaces.d/*'
  38. ovs_port_{{ interface_name }}:
  39. file.managed:
  40. - name: /etc/network/interfaces.d/ifcfg-{{ interface_name }}
  41. - source: salt://linux/files/ovs_port
  42. - defaults:
  43. port: {{ interface|yaml }}
  44. port_name: {{ interface_name }}
  45. - template: jinja
  46. ovs_port_{{ interface_name }}_line1:
  47. file.replace:
  48. - name: /etc/network/interfaces
  49. - pattern: auto {{ interface_name }}
  50. - repl: ""
  51. ovs_port_{{ interface_name }}_line2:
  52. file.replace:
  53. - name: /etc/network/interfaces
  54. - pattern: iface {{ interface_name }} inet manual
  55. - repl: ""
  56. ovs_port_up_{{ interface_name }}:
  57. cmd.run:
  58. - name: ifup {{ interface_name }}
  59. - require:
  60. - file: ovs_port_{{ interface_name }}
  61. - file: ovs_port_{{ interface_name }}_line1
  62. - file: ovs_port_{{ interface_name }}_line2
  63. - openvswitch_bridge: ovs_bridge_{{ interface.bridge }}
  64. {%- else %}
  65. linux_interface_{{ interface_name }}:
  66. network.managed:
  67. - enabled: {{ interface.enabled }}
  68. - name: {{ interface.get('name', interface_name) }}
  69. - type: {{ interface.type }}
  70. {%- if interface.address is defined %}
  71. {%- if grains.os_family == 'Debian' %}
  72. - unless: grep -q "iface {{ interface_name }} " /etc/network/interfaces
  73. - proto: {{ interface.get('proto', 'static') }}
  74. {% endif %}
  75. {%- if grains.os_family == 'RedHat' %}
  76. {%- if interface.get('proto', 'none') == 'manual' %}
  77. - proto: 'none'
  78. {%- else %}
  79. - proto: {{ interface.get('proto', 'none') }}
  80. {%- endif %}
  81. {% endif %}
  82. - ipaddr: {{ interface.address }}
  83. - netmask: {{ interface.netmask }}
  84. {%- else %}
  85. - proto: {{ interface.get('proto', 'dhcp') }}
  86. {%- endif %}
  87. {%- if interface.name_servers is defined %}
  88. - dns: {{ interface.name_servers }}
  89. {%- endif %}
  90. {%- if interface.wireless is defined and grains.os_family == 'Debian' %}
  91. {%- if interface.wireless.security == "wpa" %}
  92. - wpa-ssid: {{ interface.wireless.essid }}
  93. - wpa-psk: {{ interface.wireless.key }}
  94. {%- else %}
  95. - wireless-ssid: {{ interface.wireless.essid }}
  96. - wireless-psk: {{ interface.wireless.key }}
  97. {%- endif %}
  98. {%- endif %}
  99. {%- for param in network.interface_params %}
  100. {{ set_param(param, interface) }}
  101. {%- endfor %}
  102. {%- if interface.type == 'bridge' %}
  103. - bridge: {{ interface_name }}
  104. - delay: 0
  105. - bypassfirewall: True
  106. - use:
  107. {%- for network in interface.use_interfaces %}
  108. - network: linux_interface_{{ network }}
  109. {%- endfor %}
  110. - ports: {% for network in interface.get('use_interfaces', []) %}{{ network }} {% endfor %}{% for network in interface.get('use_ovs_ports', []) %}{{ network }} {% endfor %}
  111. - require:
  112. {%- for network in interface.get('use_interfaces', []) %}
  113. - network: linux_interface_{{ network }}
  114. {%- endfor %}
  115. {%- for network in interface.get('use_ovs_ports', []) %}
  116. - cmd: ovs_port_up_{{ network }}
  117. {%- endfor %}
  118. {%- endif %}
  119. {%- if interface.type == 'bond' %}
  120. - slaves: {{ interface.slaves }}
  121. - mode: {{ interface.mode }}
  122. {%- endif %}
  123. {%- for network in interface.get('use_ovs_ports', []) %}
  124. remove_interface_{{ network }}_line1:
  125. file.replace:
  126. - name: /etc/network/interfaces
  127. - pattern: auto {{ network }}
  128. - repl: ""
  129. remove_interface_{{ network }}_line2:
  130. file.replace:
  131. - name: /etc/network/interfaces
  132. - pattern: iface {{ network }} inet manual
  133. - repl: ""
  134. {%- endfor %}
  135. {%- if interface.gateway is defined %}
  136. linux_system_network:
  137. network.system:
  138. - enabled: {{ interface.enabled }}
  139. - hostname: {{ network.fqdn }}
  140. {%- if interface.gateway is defined %}
  141. - gateway: {{ interface.gateway }}
  142. - gatewaydev: {{ interface_name }}
  143. {%- endif %}
  144. - nozeroconf: True
  145. - nisdomain: {{ system.domain }}
  146. - require_reboot: False
  147. {%- endif %}
  148. {%- endif %}
  149. {%- endif %}
  150. {%- if interface.wireless is defined %}
  151. {%- if grains.os_family == 'Arch' %}
  152. linux_network_packages:
  153. pkg.installed:
  154. - names: {{ network.pkgs }}
  155. /etc/netctl/network_{{ interface.wireless.essid }}:
  156. file.managed:
  157. - source: salt://linux/files/wireless
  158. - mode: 755
  159. - template: jinja
  160. - require:
  161. - pkg: linux_network_packages
  162. - defaults:
  163. interface_name: {{ interface_name }}
  164. switch_profile_{{ interface.wireless.essid }}:
  165. cmd.run:
  166. - name: netctl switch-to network_{{ interface.wireless.essid }}
  167. - cwd: /root
  168. - unless: "iwconfig {{ interface_name }} | grep -e 'ESSID:\"{{ interface.wireless.essid }}\"'"
  169. - require:
  170. - file: /etc/netctl/network_{{ interface.wireless.essid }}
  171. enable_profile_{{ interface.wireless.essid }}:
  172. cmd.run:
  173. - name: netctl enable network_{{ interface.wireless.essid }}
  174. - cwd: /root
  175. - unless: test -e /etc/systemd/system/multi-user.target.wants/netctl@network_{{ interface.wireless.essid }}.service
  176. - require:
  177. - file: /etc/netctl/network_{{ interface.wireless.essid }}
  178. {%- endif %}
  179. {%- endif %}
  180. {%- endif %}
  181. {%- if interface.route is defined %}
  182. linux_network_{{ interface_name }}_routes:
  183. network.routes:
  184. - name: {{ interface_name }}
  185. - routes:
  186. {%- for route_name, route in interface.route.iteritems() %}
  187. - name: {{ route_name }}
  188. ipaddr: {{ route.address }}
  189. netmask: {{ route.netmask }}
  190. gateway: {{ route.gateway }}
  191. {%- endfor %}
  192. {%- endif %}
  193. {%- endfor %}
  194. {%- if network.bridge != 'none' %}
  195. linux_interfaces_final_include:
  196. file.prepend:
  197. - name: /etc/network/interfaces
  198. - text: 'source /etc/network/interfaces.d/*'
  199. {%- endif %}
  200. {%- endif %}
  201. {%- if network.network_manager.disable is defined and network.network_manager.disable == True %}
  202. NetworkManager:
  203. service.dead:
  204. - enable: false
  205. {%- endif %}