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.

86 line
2.6KB

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