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.

177 satır
6.0KB

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