New version of salt-formula from Saltstack
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 line
2.2KB

  1. {#- This state can be called explicitly. Do not include this file in minion.init #}
  2. {%- from "salt/map.jinja" import minion,renderer with context %}
  3. {%- if minion.enabled %}
  4. {%- if minion.source.get('engine', 'pkg') == 'pkg' %}
  5. salt_minion_packages:
  6. pkg.installed:
  7. - names: {{ minion.pkgs }}
  8. {%- if minion.source.version is defined %}
  9. - version: {{ minion.source.version }}
  10. {%- endif %}
  11. salt_minion_dependency_packages:
  12. pkg.installed:
  13. - pkgs: {{ minion.dependency_pkgs }}
  14. {%- elif minion.source.get('engine', 'pkg') == 'pip' %}
  15. salt_minion_packages:
  16. pip.installed:
  17. - name: salt{% if minion.source.version is defined %}=={{ minion.source.version }}{% endif %}
  18. salt_minion_dependency_packages:
  19. pkg.installed:
  20. - pkgs: {{ minion.dependency_pkgs_pip }}
  21. {%- endif %}
  22. /etc/salt/minion.d/minion.conf:
  23. file.managed:
  24. - source: salt://salt/files/minion.conf
  25. - user: root
  26. - group: root
  27. - template: jinja
  28. - require:
  29. - {{ minion.install_state }}
  30. {%- if renderer | length > 0 %}
  31. /etc/salt/minion.d/_renderer.conf:
  32. file.managed:
  33. - source: salt://salt/files/_renderer.conf
  34. - user: root
  35. - template: jinja
  36. - require:
  37. - {{ minion.install_state }}
  38. - watch_in:
  39. - service: salt_minion_service
  40. {%- endif %}
  41. salt_minion_service:
  42. service.running:
  43. - name: {{ minion.service }}
  44. - enable: true
  45. - require:
  46. - pkg: salt_minion_packages
  47. - pkg: salt_minion_dependency_packages
  48. {%- if grains.get('noservices') %}
  49. - onlyif: /bin/false
  50. {%- endif %}
  51. {#- Restart salt-minion if needed but after all states are executed #}
  52. salt_minion_service_restart:
  53. cmd.run:
  54. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  55. - shell: /bin/bash
  56. - bg: true
  57. - order: last
  58. - onchanges:
  59. - file: /etc/salt/minion.d/minion.conf
  60. {%- if grains.get('noservices') %}
  61. - onlyif: /bin/false
  62. {%- endif %}
  63. - require:
  64. - service: salt_minion_service
  65. salt_minion_sync_all:
  66. module.run:
  67. - name: 'saltutil.sync_all'
  68. - onchanges:
  69. - service: salt_minion_service
  70. - require:
  71. - pkg: salt_minion_packages
  72. - pkg: salt_minion_dependency_packages
  73. {%- endif %}