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