Saltstack Official Salt Formula
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

204 lines
6.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:
  28. attempts: 2
  29. until: True
  30. interval: 10
  31. splay: 10
  32. {%- elif "workaround https://github.com/saltstack/salt/issues/49348" %}
  33. cmd.run:
  34. - name: /usr/local/bin/brew install {{ salt_settings.salt_minion }}
  35. - onlyif: test -x /usr/local/bin/brew
  36. - runas: {{ salt_settings.rootuser }}
  37. {%- endif %}
  38. salt-minion-macos:
  39. file.managed:
  40. - onlyif: {{ grains.os == 'MacOS' }}
  41. - name: /Library/LaunchDaemons/com.saltstack.salt.minion.plist
  42. - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/osx/scripts/com.saltstack.salt.master.plist
  43. - source_hash: {{ salt_settings.salt_minion_macos_plist_hash }}
  44. - retry:
  45. attempts: 2
  46. until: True
  47. interval: 10
  48. splay: 10
  49. cmd.run:
  50. - names:
  51. - launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist
  52. - launchctl unload /Library/LaunchDaemons/com.saltstack.salt.minion.plist
  53. - require:
  54. - file: salt-minion-macos
  55. - require_in:
  56. - service: salt-minion
  57. {%- endif %}
  58. {%- endif %}
  59. salt-minion:
  60. {% if salt_settings.install_packages %}
  61. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  62. macpackage.installed:
  63. - name: '/tmp/salt.pkg'
  64. - target: /
  65. {# macpackage.installed is weird with version_check, detects diff but incomplete install #}
  66. - force: True {# workaround #}
  67. - unless:
  68. - test -n "{{ salt_settings.version }}" && '/opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.*'
  69. {% if salt_settings.minion_service_details.state != 'ignore' %}
  70. - require_in:
  71. - service: salt-minion
  72. {% endif %}
  73. - onchanges_in:
  74. - cmd: remove-macpackage-salt
  75. {%- elif grains.os != 'MacOS' and "workaround https://github.com/saltstack/salt/issues/49348" %}
  76. pkg.installed:
  77. - name: {{ salt_settings.salt_minion }}
  78. {%- if salt_settings.version %}
  79. - version: {{ salt_settings.version }}
  80. {%- endif %}
  81. {% if salt_settings.minion_service_details.state != 'ignore' %}
  82. - require_in:
  83. - service: salt-minion
  84. {% endif %}
  85. {%- endif %}
  86. {% endif %}
  87. file.recurse:
  88. - name: {{ salt_settings.config_path }}/minion.d
  89. {%- if salt_settings.minion_config_use_TOFS %}
  90. - template: ''
  91. - source: {{ files_switch(['minion.d'],
  92. lookup='salt-minion'
  93. )
  94. }}
  95. {%- else %}
  96. - template: jinja
  97. - source: salt://{{ tplroot }}/files/minion.d
  98. - context:
  99. standalone: False
  100. {%- endif %}
  101. - clean: {{ salt_settings.clean_config_d_dir }}
  102. - exclude_pat: _*
  103. {% if salt_settings.minion_service_details.state != 'ignore' %}
  104. service.{{ salt_settings.minion_service_details.state }}:
  105. - enable: {{ salt_settings.minion_service_details.enabled }}
  106. - name: {{ salt_settings.minion_service }}
  107. - watch:
  108. - file: salt-master-macos
  109. - file: salt-master
  110. - file: remove-old-minion-conf-file
  111. {% endif %}
  112. {%- if not salt_settings.restart_via_at %}
  113. cmd.run:
  114. {%- if grains['saltversioninfo'] >= [ 2016, 3 ] %}
  115. {%- if grains['kernel'] == 'Windows' %}
  116. - name: 'salt-call.bat --local service.restart {{ salt_settings.minion_service }}'
  117. {%- else %}
  118. - name: 'salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null'
  119. {%- endif %}
  120. - bg: True
  121. {%- else %}
  122. {%- if grains['kernel'] == 'Windows' %}
  123. - name: 'start powershell "Restart-Service -Name {{ salt_settings.minion_service }}"'
  124. {%- else %}
  125. # old style, pre 2016.3. fork and disown the process
  126. - name: |-
  127. exec 0>&- # close stdin
  128. exec 1>&- # close stdout
  129. exec 2>&- # close stderr
  130. nohup salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null &
  131. {%- endif %}
  132. {%- endif %}
  133. - onchanges:
  134. {%- if salt_settings.install_packages %}
  135. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  136. - macpackage: salt-minion
  137. {%- elif grains.os == 'MacOS' %}
  138. - cmd: download-salt-minion
  139. {%- else %}
  140. - pkg: salt-minion
  141. {%- endif %}
  142. {%- endif %}
  143. - file: salt-minion
  144. - file: remove-old-minion-conf-file
  145. {%- else %}
  146. {% if grains.os != 'MacOS' %}
  147. {# MacOS has 'at' command; but there's no package to install #}
  148. at:
  149. pkg.installed: []
  150. {% endif %}
  151. restart-salt-minion:
  152. cmd.run:
  153. - name: echo salt-call --local service.restart {{ salt_settings.minion_service }} | at now + 1 minute
  154. - order: last
  155. - require:
  156. - pkg: at
  157. - onchanges:
  158. {%- if salt_settings.install_packages %}
  159. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  160. - macpackage: salt-minion
  161. {%- elif grains.os == 'MacOS' %}
  162. - cmd: download-salt-minion
  163. {%- else %}
  164. - pkg: salt-minion
  165. {%- endif %}
  166. {%- endif %}
  167. - file: salt-minion
  168. - file: remove-old-minion-conf-file
  169. {%- endif %}
  170. {% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %}
  171. salt-minion-beacon-inotify:
  172. pkg.installed:
  173. - name: {{ salt_settings.pyinotify }}
  174. - require_in:
  175. - service: salt-minion
  176. - watch_in:
  177. - service: salt-minion
  178. {% endif %}
  179. {% if salt_settings.minion_remove_config %}
  180. remove-default-minion-conf-file:
  181. file.absent:
  182. - name: {{ salt_settings.config_path }}/minion
  183. {% endif %}
  184. # clean up old _defaults.conf file if they have it around
  185. remove-old-minion-conf-file:
  186. file.absent:
  187. - name: {{ salt_settings.config_path }}/minion.d/_defaults.conf
  188. {% if grains.os == 'MacOS' %}
  189. remove-macpackage-salt:
  190. file.absent:
  191. - name: /tmp/salt.pkg
  192. - force: True
  193. {% endif %}