New version of salt-formula from Saltstack
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

92 lines
2.3KB

  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. - mode: 600
  28. - template: jinja
  29. - require:
  30. - {{ minion.install_state }}
  31. {%- if renderer | length > 0 %}
  32. /etc/salt/minion.d/_renderer.conf:
  33. file.managed:
  34. - source: salt://salt/files/_renderer.conf
  35. - user: root
  36. - group: root
  37. - mode: 600
  38. - template: jinja
  39. - require:
  40. - {{ minion.install_state }}
  41. - watch_in:
  42. - service: salt_minion_service
  43. {%- endif %}
  44. salt_minion_service:
  45. service.running:
  46. - name: {{ minion.service }}
  47. - enable: true
  48. - require:
  49. - pkg: salt_minion_packages
  50. - pkg: salt_minion_dependency_packages
  51. {%- if grains.get('noservices') %}
  52. - onlyif: /bin/false
  53. {%- endif %}
  54. {#- Restart salt-minion if needed but after all states are executed #}
  55. salt_minion_service_restart:
  56. cmd.run:
  57. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  58. - shell: /bin/bash
  59. - bg: true
  60. - order: last
  61. - onchanges:
  62. - file: /etc/salt/minion.d/minion.conf
  63. {%- if grains.get('noservices') %}
  64. - onlyif: /bin/false
  65. {%- endif %}
  66. - require:
  67. - service: salt_minion_service
  68. salt_minion_sync_all:
  69. module.run:
  70. - name: 'saltutil.sync_all'
  71. - onchanges:
  72. - service: salt_minion_service
  73. - require:
  74. - pkg: salt_minion_packages
  75. - pkg: salt_minion_dependency_packages
  76. {%- endif %}