Saltstack Official Salt Formula
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

minion.sls 5.8KB

7 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. {% if salt_settings.minion_service_details.state != 'ignore' %}
  43. - require_in:
  44. - service: salt-minion
  45. {% endif %}
  46. - onchanges_in:
  47. - cmd: remove-macpackage-salt
  48. {%- elif grains.os != 'MacOS' and "workaround https://github.com/saltstack/salt/issues/49348" %}
  49. pkg.installed:
  50. - name: {{ salt_settings.salt_minion }}
  51. {%- if salt_settings.version %}
  52. - version: {{ salt_settings.version }}
  53. {%- endif %}
  54. {% if salt_settings.minion_service_details.state != 'ignore' %}
  55. - require_in:
  56. - service: salt-minion
  57. {% endif %}
  58. {%- endif %}
  59. {% endif %}
  60. file.recurse:
  61. - name: {{ salt_settings.config_path }}/minion.d
  62. {%- if salt_settings.minion_config_use_TOFS %}
  63. - template: ''
  64. - source: {{ files_switch(['minion.d'],
  65. lookup='salt-minion'
  66. )
  67. }}
  68. {%- else %}
  69. - template: jinja
  70. - source: salt://{{ tplroot }}/files/minion.d
  71. - context:
  72. standalone: False
  73. {%- endif %}
  74. - clean: {{ salt_settings.clean_config_d_dir }}
  75. - exclude_pat: _*
  76. {% if salt_settings.minion_service_details.state != 'ignore' %}
  77. service.{{ salt_settings.minion_service_details.state }}:
  78. - enable: {{ salt_settings.minion_service_details.enabled }}
  79. - name: {{ salt_settings.minion_service }}
  80. - require:
  81. - file: salt-minion
  82. {% endif %}
  83. {%- if not salt_settings.restart_via_at %}
  84. cmd.run:
  85. {%- if grains['saltversioninfo'] >= [ 2016, 3 ] %}
  86. {%- if grains['kernel'] == 'Windows' %}
  87. - name: 'salt-call.bat --local service.restart {{ salt_settings.minion_service }}'
  88. {%- else %}
  89. - name: 'salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null'
  90. {%- endif %}
  91. - bg: True
  92. {%- else %}
  93. {%- if grains['kernel'] == 'Windows' %}
  94. - name: 'start powershell "Restart-Service -Name {{ salt_settings.minion_service }}"'
  95. {%- else %}
  96. # old style, pre 2016.3. fork and disown the process
  97. - name: |-
  98. exec 0>&- # close stdin
  99. exec 1>&- # close stdout
  100. exec 2>&- # close stderr
  101. nohup salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null &
  102. {%- endif %}
  103. {%- endif %}
  104. - onchanges:
  105. {%- if salt_settings.install_packages %}
  106. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  107. - macpackage: salt-minion
  108. {%- elif grains.os == 'MacOS' %}
  109. - cmd: download-salt-minion
  110. {%- else %}
  111. - pkg: salt-minion
  112. {%- endif %}
  113. {%- endif %}
  114. - file: salt-minion
  115. - file: remove-old-minion-conf-file
  116. {%- else %}
  117. {% if grains.os != 'MacOS' %}
  118. {# MacOS has 'at' command; but there's no package to install #}
  119. at:
  120. pkg.installed: []
  121. {% endif %}
  122. restart-salt-minion:
  123. cmd.run:
  124. - name: echo salt-call --local service.restart {{ salt_settings.minion_service }} | at now + 1 minute
  125. - order: last
  126. - require:
  127. - pkg: at
  128. - onchanges:
  129. {%- if salt_settings.install_packages %}
  130. {%- if grains.os == 'MacOS' and salt_settings.salt_minion_pkg_source %}
  131. - macpackage: salt-minion
  132. {%- elif grains.os == 'MacOS' %}
  133. - cmd: download-salt-minion
  134. {%- else %}
  135. - pkg: salt-minion
  136. {%- endif %}
  137. {%- endif %}
  138. - file: salt-minion
  139. - file: remove-old-minion-conf-file
  140. {%- endif %}
  141. {% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %}
  142. salt-minion-beacon-inotify:
  143. pkg.installed:
  144. - name: {{ salt_settings.pyinotify }}
  145. - require_in:
  146. - service: salt-minion
  147. - watch_in:
  148. - service: salt-minion
  149. {% endif %}
  150. {% if salt_settings.minion_remove_config %}
  151. remove-default-minion-conf-file:
  152. file.absent:
  153. - name: {{ salt_settings.config_path }}/minion
  154. {% endif %}
  155. # clean up old _defaults.conf file if they have it around
  156. remove-old-minion-conf-file:
  157. file.absent:
  158. - name: {{ salt_settings.config_path }}/minion.d/_defaults.conf
  159. {% if grains.os == 'MacOS' %}
  160. remove-macpackage-salt:
  161. file.absent:
  162. - name: /tmp/salt.pkg
  163. - force: True
  164. {% endif %}