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.

89 lines
2.6KB

  1. {% from "salt/map.jinja" import salt_settings with context %}
  2. {% if grains.os != "MacOS" %}
  3. salt-minion:
  4. {% if salt_settings.install_packages %}
  5. pkg.installed:
  6. - name: {{ salt_settings.salt_minion }}
  7. {% endif %}
  8. file.recurse:
  9. - name: {{ salt_settings.config_path }}/minion.d
  10. - template: jinja
  11. - source: salt://{{ slspath }}/files/minion.d
  12. - clean: {{ salt_settings.clean_config_d_dir }}
  13. - exclude_pat: _*
  14. - context:
  15. standalone: False
  16. service.running:
  17. - enable: True
  18. - name: {{ salt_settings.minion_service }}
  19. - require:
  20. - file: salt-minion
  21. {%- if not salt_settings.restart_via_at %}
  22. cmd.run:
  23. {%- if grains['saltversioninfo'][0] >= 2016 and grains['saltversioninfo'][1] >= 3 %}
  24. {%- if grains['kernel'] == 'Windows' %}
  25. - name: 'salt-call.bat --local service.restart {{ salt_settings.minion_service }}'
  26. {%- else %}
  27. - name: 'salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null'
  28. {%- endif %}
  29. - bg: True
  30. {%- else %}
  31. {%- if grains['kernel'] == 'Windows' %}
  32. - name: 'start powershell "Restart-Service -Name {{ salt_settings.minion_service }}"'
  33. {%- else %}
  34. # old style, pre 2016.3. fork and disown the process
  35. - name: |-
  36. exec 0>&- # close stdin
  37. exec 1>&- # close stdout
  38. exec 2>&- # close stderr
  39. nohup salt-call --local service.restart {{ salt_settings.minion_service }} --out-file /dev/null &
  40. {%- endif %}
  41. {%- endif %}
  42. - onchanges:
  43. {%- if salt_settings.install_packages %}
  44. - pkg: salt-minion
  45. {%- endif %}
  46. - file: salt-minion
  47. - file: remove-old-minion-conf-file
  48. {%- else %}
  49. at:
  50. pkg.installed: []
  51. restart-salt-minion:
  52. cmd.run:
  53. - name: echo salt-call --local service.restart salt-minion | at now + 1 minute
  54. - order: last
  55. - require:
  56. - pkg: at
  57. - onchanges:
  58. {%- if salt_settings.install_packages %}
  59. - pkg: salt-minion
  60. {%- endif %}
  61. - file: salt-minion
  62. - file: remove-old-minion-conf-file
  63. {%- endif %}
  64. {% if 'inotify' in salt_settings.get('minion', {}).get('beacons', {}) and salt_settings.get('pyinotify', False) %}
  65. salt-minion-beacon-inotify:
  66. pkg.installed:
  67. - name: {{ salt_settings.pyinotify }}
  68. - require_in:
  69. - service: salt-minion
  70. - watch_in:
  71. - service: salt-minion
  72. {% endif %}
  73. {% if salt_settings.minion_remove_config %}
  74. remove-default-minion-conf-file:
  75. file.absent:
  76. - name: {{ salt_settings.config_path }}/minion
  77. {% endif %}
  78. # clean up old _defaults.conf file if they have it around
  79. remove-old-minion-conf-file:
  80. file.absent:
  81. - name: {{ salt_settings.config_path }}/minion.d/_defaults.conf
  82. {% endif %}