Saltstack Official Salt Formula
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

178 líneas
5.9KB

  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 != 'MacOS' %}
  122. {# MacOS has 'at' command; but there's no package to install #}
  123. at:
  124. pkg.installed: []
  125. {% endif %}
  126. restart-salt-minion:
  127. cmd.run:
  128. - name: echo salt-call --local service.restart {{ salt_settings.minion_service }} | at now + 1 minute
  129. - order: last
  130. - require:
  131. - pkg: at
  132. - onchanges:
  133. {%- if salt_settings.install_packages %}
  134. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  135. - macpackage: salt-minion
  136. {%- elif grains.os == 'MacOS' %}
  137. - cmd: download-salt-minion
  138. {%- else %}
  139. - pkg: salt-minion
  140. {%- endif %}
  141. {%- endif %}
  142. - file: salt-minion
  143. - file: remove-old-minion-conf-file
  144. {%- endif %}
  145. {% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %}
  146. salt-minion-beacon-inotify:
  147. pkg.installed:
  148. - name: {{ salt_settings.pyinotify }}
  149. - require_in:
  150. - service: salt-minion
  151. - watch_in:
  152. - service: salt-minion
  153. {% endif %}
  154. {% if salt_settings.minion_remove_config %}
  155. remove-default-minion-conf-file:
  156. file.absent:
  157. - name: {{ salt_settings.config_path }}/minion
  158. {% endif %}
  159. # clean up old _defaults.conf file if they have it around
  160. remove-old-minion-conf-file:
  161. file.absent:
  162. - name: {{ salt_settings.config_path }}/minion.d/_defaults.conf
  163. {% if grains.os == 'MacOS' %}
  164. remove-macpackage-salt:
  165. file.absent:
  166. - name: /tmp/salt.pkg
  167. - force: True
  168. {% endif %}