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.

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