Saltstack Official Salt Formula
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

198 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. {% endif %}
  106. {%- if not salt_settings.restart_via_at %}
  107. cmd.run:
  108. {%- if grains['saltversioninfo'] >= [ 2016, 3 ] %}
  109. {%- if grains['kernel'] == 'Windows' %}
  110. - name: 'salt-call.bat --local service.restart {{ salt_settings.minion_service }}'
  111. {%- else %}
  112. - name: 'salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null'
  113. {%- endif %}
  114. - bg: True
  115. {%- else %}
  116. {%- if grains['kernel'] == 'Windows' %}
  117. - name: 'start powershell "Restart-Service -Name {{ salt_settings.minion_service }}"'
  118. {%- else %}
  119. # old style, pre 2016.3. fork and disown the process
  120. - name: |-
  121. exec 0>&- # close stdin
  122. exec 1>&- # close stdout
  123. exec 2>&- # close stderr
  124. nohup salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null &
  125. {%- endif %}
  126. {%- endif %}
  127. - onchanges:
  128. {%- if salt_settings.install_packages %}
  129. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  130. - macpackage: salt-minion
  131. {%- elif grains.os == 'MacOS' %}
  132. - cmd: download-salt-minion
  133. {%- else %}
  134. - pkg: salt-minion
  135. {%- endif %}
  136. {%- endif %}
  137. - file: salt-minion
  138. - file: remove-old-minion-conf-file
  139. {%- else %}
  140. {% if grains.os_family not in ['MacOS', 'FreeBSD'] %}
  141. {# MacOS and FreeBSD have the 'at' command; but there's no package to install #}
  142. at:
  143. pkg.installed:
  144. - require_in: restart-salt-minion
  145. {% endif %}
  146. restart-salt-minion:
  147. cmd.run:
  148. - name: echo salt-call --local service.restart {{ salt_settings.minion_service }} | at now + 1 minute
  149. - order: last
  150. - onchanges:
  151. {%- if salt_settings.install_packages %}
  152. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  153. - macpackage: salt-minion
  154. {%- elif grains.os == 'MacOS' %}
  155. - cmd: download-salt-minion
  156. {%- else %}
  157. - pkg: salt-minion
  158. {%- endif %}
  159. {%- endif %}
  160. - file: salt-minion
  161. - file: remove-old-minion-conf-file
  162. {%- endif %}
  163. {% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %}
  164. salt-minion-beacon-inotify:
  165. pkg.installed:
  166. - name: {{ salt_settings.pyinotify }}
  167. - require_in:
  168. - service: salt-minion
  169. - watch_in:
  170. - service: salt-minion
  171. {% endif %}
  172. {% if salt_settings.minion_remove_config %}
  173. remove-default-minion-conf-file:
  174. file.absent:
  175. - name: {{ salt_settings.config_path }}/minion
  176. {% endif %}
  177. # clean up old _defaults.conf file if they have it around
  178. remove-old-minion-conf-file:
  179. file.absent:
  180. - name: {{ salt_settings.config_path }}/minion.d/_defaults.conf
  181. {% if grains.os == 'MacOS' %}
  182. remove-macpackage-salt:
  183. file.absent:
  184. - name: /tmp/salt.pkg
  185. - force: True
  186. {% endif %}