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.

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