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

199 lines
6.7KB

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