Saltstack Official Salt Formula
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

270 líneas
8.9KB

  1. {%- set tplroot = tpldir.split('/')[0] %}
  2. {%- from tplroot ~ "/map.jinja" import salt_settings with context %}
  3. {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
  4. {% if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %}
  5. include:
  6. - .pin
  7. {% endif %}
  8. {%- if grains.os == 'MacOS' %}
  9. {% if salt_settings.install_packages %}
  10. download-salt-minion:
  11. {% if salt_settings.salt_minion_pkg_source %} {# minion upgrade? #}
  12. file.managed:
  13. - name: '/tmp/salt.pkg'
  14. - source: {{ salt_settings.salt_minion_pkg_source }}
  15. {%- if salt_settings.salt_minion_pkg_hash %}
  16. - source_hash: {{ salt_settings.salt_minion_pkg_hash }}
  17. {% else %}
  18. - skip_verify: True
  19. {% endif %}
  20. - user: root
  21. - group: wheel
  22. - mode: '0644'
  23. - unless:
  24. - test -n "{{ salt_settings.version }}" && '/opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.*'
  25. - require_in:
  26. - macpackage: salt-minion
  27. - retry: {{ salt_settings.retry_options | json }}
  28. {%- elif "workaround https://github.com/saltstack/salt/issues/49348" %}
  29. cmd.run:
  30. - name: /usr/local/bin/brew install {{ salt_settings.salt_minion }}
  31. - onlyif: test -x /usr/local/bin/brew
  32. - runas: {{ salt_settings.rootuser }}
  33. {%- endif %}
  34. salt-minion-macos:
  35. file.managed:
  36. - onlyif: {{ grains.os == 'MacOS' }}
  37. - name: /Library/LaunchDaemons/com.saltstack.salt.minion.plist
  38. - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/osx/scripts/com.saltstack.salt.master.plist
  39. - source_hash: {{ salt_settings.salt_minion_macos_plist_hash }}
  40. - retry: {{ salt_settings.retry_options | json }}
  41. - require_in:
  42. - service: salt-minion
  43. - watch_in:
  44. - service: salt-minion
  45. {%- endif %}
  46. {%- endif %}
  47. salt-minion:
  48. {% if salt_settings.install_packages %}
  49. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  50. macpackage.installed:
  51. - name: '/tmp/salt.pkg'
  52. - target: /
  53. {# macpackage.installed is weird with version_check, detects diff but incomplete install #}
  54. - force: True {# workaround #}
  55. - unless:
  56. - test -n "{{ salt_settings.version }}" && '/opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.*'
  57. {% if salt_settings.minion_service_details.state != 'ignore' %}
  58. - require_in:
  59. - service: salt-minion
  60. {% endif %}
  61. - onchanges_in:
  62. - cmd: remove-macpackage-salt
  63. {%- elif grains.os != 'MacOS' and "workaround https://github.com/saltstack/salt/issues/49348" %}
  64. pkg.installed:
  65. - name: {{ salt_settings.salt_minion }}
  66. {%- if salt_settings.version %}
  67. - version: {{ salt_settings.version }}
  68. {%- endif %}
  69. {% if salt_settings.minion_service_details.state != 'ignore' %}
  70. - require_in:
  71. - service: salt-minion
  72. {% endif %}
  73. {%- endif %}
  74. {% endif %}
  75. file.recurse:
  76. - name: {{ salt_settings.config_path | path_join('minion.d') }}
  77. {%- if salt_settings.minion_config_use_TOFS %}
  78. - template: ''
  79. - source: {{ files_switch(['minion.d'],
  80. lookup='salt-minion'
  81. )
  82. }}
  83. {%- else %}
  84. - template: jinja
  85. - source: salt://{{ tplroot }}/files/minion.d
  86. - context:
  87. standalone: False
  88. {%- endif %}
  89. - clean: {{ salt_settings.clean_config_d_dir }}
  90. - exclude_pat: _*
  91. {% if salt_settings.minion_service_details.state != 'ignore' %}
  92. service.{{ salt_settings.minion_service_details.state }}:
  93. - enable: {{ salt_settings.minion_service_details.enabled }}
  94. - name: {{ salt_settings.minion_service }}
  95. {%- if grains.os_family == 'FreeBSD' %}
  96. - retry: {{ salt_settings.retry_options | json }}
  97. {%- endif %}
  98. - watch:
  99. - file: remove-old-minion-conf-file
  100. - order: last
  101. {% endif %}
  102. {%- if not salt_settings.restart_via_at %}
  103. cmd.run:
  104. {%- if grains['saltversioninfo'] >= [ 2016, 3 ] %}
  105. {%- if grains['kernel'] == 'Windows' %}
  106. - name: 'salt-call.bat --local service.restart {{ salt_settings.minion_service }}'
  107. {%- else %}
  108. - name: 'salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null'
  109. {%- endif %}
  110. - bg: True
  111. {%- else %}
  112. {%- if grains['kernel'] == 'Windows' %}
  113. - name: 'start powershell "Restart-Service -Name {{ salt_settings.minion_service }}"'
  114. {%- else %}
  115. # old style, pre 2016.3. fork and disown the process
  116. - name: |-
  117. exec 0>&- # close stdin
  118. exec 1>&- # close stdout
  119. exec 2>&- # close stderr
  120. nohup salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null &
  121. {%- endif %}
  122. {%- endif %}
  123. - onchanges:
  124. {%- if salt_settings.install_packages %}
  125. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  126. - macpackage: salt-minion
  127. {%- elif grains.os == 'MacOS' %}
  128. - cmd: download-salt-minion
  129. {%- else %}
  130. - pkg: salt-minion
  131. {%- endif %}
  132. {%- endif %}
  133. - file: salt-minion
  134. - file: remove-old-minion-conf-file
  135. {%- else %}
  136. {% if grains.os_family not in ['MacOS', 'FreeBSD'] %}
  137. {# MacOS and FreeBSD have the 'at' command; but there's no package to install #}
  138. at:
  139. pkg.installed:
  140. - require_in: restart-salt-minion
  141. {% endif %}
  142. restart-salt-minion:
  143. cmd.run:
  144. - name: echo salt-call --local service.restart {{ salt_settings.minion_service }} | at now + 1 minute
  145. - order: last
  146. - onchanges:
  147. {%- if salt_settings.install_packages %}
  148. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  149. - macpackage: salt-minion
  150. {%- elif grains.os == 'MacOS' %}
  151. - cmd: download-salt-minion
  152. {%- else %}
  153. - pkg: salt-minion
  154. {%- endif %}
  155. {%- endif %}
  156. - file: salt-minion
  157. - file: remove-old-minion-conf-file
  158. {%- endif %}
  159. {% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %}
  160. salt-minion-beacon-inotify:
  161. pkg.installed:
  162. - name: {{ salt_settings.pyinotify }}
  163. - require_in:
  164. - service: salt-minion
  165. - watch_in:
  166. - service: salt-minion
  167. {% endif %}
  168. {% if salt_settings.minion_remove_config %}
  169. remove-default-minion-conf-file:
  170. file.absent:
  171. - name: {{ salt_settings.config_path }}/minion
  172. {% endif %}
  173. # clean up old _defaults.conf file if they have it around
  174. remove-old-minion-conf-file:
  175. file.absent:
  176. - name: {{ salt_settings.config_path | path_join('minion.d', '_defaults.conf') }}
  177. {% if grains.os == 'MacOS' %}
  178. remove-macpackage-salt:
  179. file.absent:
  180. - name: /tmp/salt.pkg
  181. - force: True
  182. {% endif %}
  183. permissions-minion-config:
  184. file.managed:
  185. - name: {{ salt_settings.config_path | path_join('minion') }}
  186. - user: {{ salt_settings.rootuser }}
  187. - group:
  188. {%- if grains['kernel'] in ['FreeBSD', 'OpenBSD', 'NetBSD'] %}
  189. wheel
  190. {%- else %}
  191. root
  192. {%- endif %}
  193. {%- if grains['kernel'] != 'Windows' %}
  194. - mode: 640
  195. {% endif %}
  196. - replace: False
  197. salt-minion-pki-dir:
  198. file.directory:
  199. {% if 'pki_dir' in salt_settings.minion %}
  200. - name: {{ salt_settings.minion.pki_dir }}
  201. {% else %}
  202. - name: {{ salt_settings.config_path | path_join('pki', 'minion') }}
  203. {% endif %}
  204. - user: {{ salt_settings.rootuser }}
  205. - group:
  206. {%- if grains['kernel'] in ['FreeBSD', 'OpenBSD', 'NetBSD'] %}
  207. wheel
  208. {%- else %}
  209. root
  210. {%- endif %}
  211. {%- if grains['kernel'] != 'Windows' %}
  212. - mode: 700
  213. {% endif %}
  214. - makedirs: True
  215. permissions-minion.pem:
  216. file.managed:
  217. {% if 'pki_dir' in salt_settings.minion %}
  218. - name: {{ salt_settings.minion.pki_dir | path_join('minion.pem') }}
  219. {% else %}
  220. - name: {{ salt_settings.config_path | path_join('pki', 'minion', 'minion.pem') }}
  221. {% endif %}
  222. - user: {{ salt_settings.rootuser }}
  223. - group:
  224. {%- if grains['kernel'] in ['FreeBSD', 'OpenBSD', 'NetBSD'] %}
  225. wheel
  226. {%- else %}
  227. root
  228. {%- endif %}
  229. {%- if grains['kernel'] != 'Windows' %}
  230. - mode: 400
  231. {% endif %}
  232. - replace: False
  233. - require:
  234. - file: salt-minion-pki-dir
  235. permissions-minion.pub:
  236. file.managed:
  237. {% if 'pki_dir' in salt_settings.minion %}
  238. - name: {{ salt_settings.minion.pki_dir | path_join('minion.pub') }}
  239. {% else %}
  240. - name: {{ salt_settings.config_path | path_join('pki', 'minion', 'minion.pub') }}
  241. {% endif %}
  242. - user: {{ salt_settings.rootuser }}
  243. - group:
  244. {%- if grains['kernel'] in ['FreeBSD', 'OpenBSD', 'NetBSD'] %}
  245. wheel
  246. {%- else %}
  247. root
  248. {%- endif %}
  249. {%- if grains['kernel'] != 'Windows' %}
  250. - mode: 644
  251. {% endif %}
  252. - replace: False
  253. - require:
  254. - file: salt-minion-pki-dir