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.

140 lines
4.5KB

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