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.

пре 11 година
пре 5 година
пре 11 година
пре 5 година
пре 11 година
пре 11 година
пре 7 година
пре 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 grains.os == 'MacOS' %}
  5. {% if salt_settings.install_packages %}
  6. download-salt-minion:
  7. {% if salt_settings.salt_minion_pkg_source %}
  8. {# only IF we know source and version to check the current install (if installed) against #}
  9. {# e.g. don't download unless a minion upgrade is happening #}
  10. file.managed:
  11. - name: '/tmp/salt.pkg'
  12. - source: {{ salt_settings.salt_minion_pkg_source }}
  13. {%- if salt_settings.salt_minion_pkg_hash %}
  14. - source_hash: {{ salt_settings.salt_minion_pkg_hash }}
  15. {% else %}
  16. - skip_verify: True
  17. {% endif %}
  18. - user: root
  19. - group: wheel
  20. - mode: '0644'
  21. - unless:
  22. - test -n "{{ salt_settings.version }}" && '/opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.*'
  23. - require_in:
  24. - macpackage: salt-minion
  25. - retry:
  26. attempts: 2
  27. until: True
  28. interval: 10
  29. splay: 10
  30. {%- elif "workaround https://github.com/saltstack/salt/issues/49348" %}
  31. cmd.run:
  32. - name: /usr/local/bin/brew install {{ salt_settings.salt_minion }}
  33. - onlyif: test -x /usr/local/bin/brew
  34. - runas: {{ salt_settings.rootuser }}
  35. {%- endif %}
  36. salt-minion-macos:
  37. file.managed:
  38. - onlyif: {{ grains.os == 'MacOS' }}
  39. - name: /Library/LaunchDaemons/com.saltstack.salt.minion.plist
  40. - source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/darwin/com.saltstack.salt.minion.plist
  41. - source_hash: {{ salt_settings.salt_minion_macos_plist_hash }}
  42. - retry:
  43. attempts: 2
  44. until: True
  45. interval: 10
  46. splay: 10
  47. cmd.run:
  48. - names:
  49. - launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist
  50. - launchctl unload /Library/LaunchDaemons/com.saltstack.salt.minion.plist
  51. - require:
  52. - file: salt-minion-macos
  53. - require_in:
  54. - service: salt-minion
  55. {%- endif %}
  56. {%- endif %}
  57. salt-minion:
  58. {% if salt_settings.install_packages %}
  59. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  60. macpackage.installed:
  61. - name: '/tmp/salt.pkg'
  62. - target: /
  63. {# macpackage.installed behaves weirdly with version_check, detects diff but fails to complete install. #}
  64. {# use force == True as workaround #}
  65. - force: True
  66. - unless:
  67. - test -n "{{ salt_settings.version }}" && '/opt/salt/bin/salt-minion --version=.*{{ salt_settings.version }}.*'
  68. - require_in:
  69. - service: salt-minion
  70. - onchanges_in:
  71. - cmd: remove-macpackage-salt
  72. {%- elif grains.os != 'MacOS' and "workaround https://github.com/saltstack/salt/issues/49348" %}
  73. pkg.installed:
  74. - name: {{ salt_settings.salt_minion }}
  75. {%- if salt_settings.version %}
  76. - version: {{ salt_settings.version }}
  77. {%- endif %}
  78. - require_in:
  79. - service: salt-minion
  80. {%- endif %}
  81. {% endif %}
  82. file.recurse:
  83. - name: {{ salt_settings.config_path }}/minion.d
  84. {%- if salt_settings.minion_config_use_TOFS %}
  85. - template: ''
  86. - source: {{ files_switch(['minion.d'],
  87. lookup='salt-minion'
  88. )
  89. }}
  90. {%- else %}
  91. - template: jinja
  92. - source: salt://{{ slspath }}/files/minion.d
  93. - context:
  94. standalone: False
  95. {%- endif %}
  96. - clean: {{ salt_settings.clean_config_d_dir }}
  97. - exclude_pat: _*
  98. service.running:
  99. - enable: True
  100. - name: {{ salt_settings.minion_service }}
  101. - require:
  102. - file: salt-minion
  103. {%- if not salt_settings.restart_via_at %}
  104. cmd.run:
  105. {%- if grains['saltversioninfo'] >= [ 2016, 3 ] %}
  106. {%- if grains['kernel'] == 'Windows' %}
  107. - name: 'salt-call.bat --local service.restart {{ salt_settings.minion_service }}'
  108. {%- else %}
  109. - name: 'salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null'
  110. {%- endif %}
  111. - bg: True
  112. {%- else %}
  113. {%- if grains['kernel'] == 'Windows' %}
  114. - name: 'start powershell "Restart-Service -Name {{ salt_settings.minion_service }}"'
  115. {%- else %}
  116. # old style, pre 2016.3. fork and disown the process
  117. - name: |-
  118. exec 0>&- # close stdin
  119. exec 1>&- # close stdout
  120. exec 2>&- # close stderr
  121. nohup salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null &
  122. {%- endif %}
  123. {%- endif %}
  124. - onchanges:
  125. {%- if salt_settings.install_packages %}
  126. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  127. - macpackage: salt-minion
  128. {%- elif grains.os == 'MacOS' %}
  129. - cmd: download-salt-minion
  130. {%- else %}
  131. - pkg: salt-minion
  132. {%- endif %}
  133. {%- endif %}
  134. - file: salt-minion
  135. - file: remove-old-minion-conf-file
  136. {%- else %}
  137. {% if grains.os != 'MacOS' %}
  138. {# MacOS has 'at' command; but there's no package to install #}
  139. at:
  140. pkg.installed: []
  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. - require:
  147. - pkg: at
  148. - onchanges:
  149. {%- if salt_settings.install_packages %}
  150. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  151. - macpackage: salt-minion
  152. {%- elif grains.os == 'MacOS' %}
  153. - cmd: download-salt-minion
  154. {%- else %}
  155. - pkg: salt-minion
  156. {%- endif %}
  157. {%- endif %}
  158. - file: salt-minion
  159. - file: remove-old-minion-conf-file
  160. {%- endif %}
  161. {% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %}
  162. salt-minion-beacon-inotify:
  163. pkg.installed:
  164. - name: {{ salt_settings.pyinotify }}
  165. - require_in:
  166. - service: salt-minion
  167. - watch_in:
  168. - service: salt-minion
  169. {% endif %}
  170. {% if salt_settings.minion_remove_config %}
  171. remove-default-minion-conf-file:
  172. file.absent:
  173. - name: {{ salt_settings.config_path }}/minion
  174. {% endif %}
  175. # clean up old _defaults.conf file if they have it around
  176. remove-old-minion-conf-file:
  177. file.absent:
  178. - name: {{ salt_settings.config_path }}/minion.d/_defaults.conf
  179. {% if grains.os == 'MacOS' %}
  180. remove-macpackage-salt:
  181. file.absent:
  182. - name: /tmp/salt.pkg
  183. - force: True
  184. {% endif %}