New version of salt-formula from Saltstack
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

170 lines
4.6KB

  1. {%- from "salt/map.jinja" import minion,renderer with context %}
  2. {%- if minion.enabled %}
  3. {%- if minion.source.get('engine', 'pkg') == 'pkg' %}
  4. salt_minion_packages:
  5. pkg.installed:
  6. - names: {{ minion.pkgs }}
  7. {%- if minion.source.version is defined %}
  8. - version: {{ minion.source.version }}
  9. {%- endif %}
  10. salt_minion_dependency_packages:
  11. pkg.installed:
  12. - pkgs: {{ minion.dependency_pkgs }}
  13. {%- elif minion.source.get('engine', 'pkg') == 'pip' %}
  14. salt_minion_packages:
  15. pip.installed:
  16. - name: salt{% if minion.source.version is defined %}=={{ minion.source.version }}{% endif %}
  17. salt_minion_dependency_packages:
  18. pkg.installed:
  19. - pkgs: {{ minion.dependency_pkgs_pip }}
  20. {%- endif %}
  21. /etc/salt/minion.d/minion.conf:
  22. file.managed:
  23. - source: salt://salt/files/minion.conf
  24. - user: root
  25. - group: root
  26. - mode: 600
  27. - template: jinja
  28. - require:
  29. - {{ minion.install_state }}
  30. {%- for service_name, service in pillar.items() %}
  31. {%- set support_fragment_file = service_name+'/meta/salt.yml' %}
  32. {%- macro load_support_file() %}{% include support_fragment_file ignore missing %}{% endmacro %}
  33. {%- set support_yaml = load_support_file()|load_yaml %}
  34. {%- if support_yaml and support_yaml.get('minion', {}) %}
  35. {%- for name, conf in support_yaml.get('minion', {}).iteritems() %}
  36. salt_minion_config_{{ service_name }}_{{ name }}:
  37. file.managed:
  38. - name: /etc/salt/minion.d/_{{ name }}.conf
  39. - user: root
  40. - group: root
  41. - mode: 600
  42. - contents: |
  43. {{ conf|yaml(False)|indent(8) }}
  44. - require:
  45. - {{ minion.install_state }}
  46. salt_minion_config_{{ service_name }}_{{ name }}_validity_check:
  47. cmd.run:
  48. - name: python -c "import yaml; stream = file('/etc/salt/minion.d/_{{ name }}.conf', 'r'); yaml.load(stream); stream.close()"
  49. - onchanges:
  50. - file: salt_minion_config_{{ service_name }}_{{ name }}
  51. - onchanges_in:
  52. - cmd: salt_minion_service_restart
  53. {%- endfor %}
  54. {%- endif %}
  55. {%- if support_yaml %}
  56. {%- set dependency = support_yaml.get('dependency') %}
  57. {%- if dependency %}
  58. {%- if dependency.get('engine', 'pkg') == 'pkg' %}
  59. salt_minion_{{ service_name }}_dependencies:
  60. pkg.installed:
  61. - names: {{ dependency.get('pkgs') }}
  62. - onchanges_in:
  63. - cmd: salt_minion_service_restart
  64. {%- elif dependency.get('engine', 'pkg') == 'pip' %}
  65. {%- if dependency.get('pkgs') %}
  66. salt_minion_{{ service_name }}_dependencies:
  67. pkg.installed:
  68. - names: {{ dependency.get('pkgs') }}
  69. - onchanges_in:
  70. - cmd: salt_minion_service_restart
  71. - require_in:
  72. - pip: salt_minion_{{ service_name }}_dependencies_pip
  73. {%- endif %}
  74. salt_minion_{{ service_name }}_dependencies_pip:
  75. pip.installed:
  76. - names: {{ dependency.get('python_pkgs') }}
  77. - onchanges_in:
  78. - cmd: salt_minion_service_restart
  79. {%- endif %}
  80. {%- endif %}
  81. {%- endif %}
  82. {%- endfor %}
  83. {%- if renderer | length > 0 %}
  84. /etc/salt/minion.d/_renderer.conf:
  85. file.managed:
  86. - source: salt://salt/files/_renderer.conf
  87. - user: root
  88. - group: root
  89. - mode: 600
  90. - template: jinja
  91. - require:
  92. - {{ minion.install_state }}
  93. - watch_in:
  94. - service: salt_minion_service
  95. {%- endif %}
  96. salt_minion_service:
  97. service.running:
  98. - name: {{ minion.service }}
  99. - enable: true
  100. - require:
  101. - pkg: salt_minion_packages
  102. - pkg: salt_minion_dependency_packages
  103. {%- if grains.get('noservices') %}
  104. - onlyif: /bin/false
  105. {%- endif %}
  106. {%- if grains.get('init', None) == 'systemd' %}
  107. salt_minion_systemd_override:
  108. file.managed:
  109. - name: /etc/systemd/system/{{ minion.service }}.service.d/50-restarts.conf
  110. - source: salt://salt/files/systemd/{{ minion.service }}.service_50-restarts
  111. - makedirs: True
  112. salt_minion_systemd_reload:
  113. module.wait:
  114. - name: service.systemctl_reload
  115. - onchanges:
  116. - file: salt_minion_systemd_override
  117. - watch_in:
  118. - service: salt_minion_service
  119. {%- endif %}
  120. {#- Restart salt-minion if needed but after all states are executed #}
  121. salt_minion_service_restart:
  122. cmd.run:
  123. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  124. - shell: /bin/bash
  125. - bg: true
  126. - order: last
  127. - onchanges:
  128. - file: /etc/salt/minion.d/minion.conf
  129. {%- if grains.get('noservices') %}
  130. - onlyif: /bin/false
  131. {%- endif %}
  132. - require:
  133. - service: salt_minion_service
  134. salt_minion_sync_all:
  135. module.run:
  136. - name: 'saltutil.sync_all'
  137. - onchanges:
  138. - service: salt_minion_service
  139. - require:
  140. - pkg: salt_minion_packages
  141. - pkg: salt_minion_dependency_packages
  142. {%- endif %}