Saltstack Official Salt Formula
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

11 роки тому
5 роки тому
11 роки тому
5 роки тому
11 роки тому
11 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 }}/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 }}/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 %}