Saltstack Official Linux 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.

interface.sls 6.2KB

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