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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. - template: jinja
  27. - require:
  28. - {{ minion.install_state }}
  29. {%- for service_name, service in pillar.items() %}
  30. {%- set support_fragment_file = service_name+'/meta/salt.yml' %}
  31. {%- macro load_support_file() %}{% include support_fragment_file ignore missing %}{% endmacro %}
  32. {%- set support_yaml = load_support_file()|load_yaml %}
  33. {%- if support_yaml and support_yaml.get('minion', {}) %}
  34. {%- for name, conf in support_yaml.get('minion', {}).iteritems() %}
  35. salt_minion_config_{{ service_name }}_{{ name }}:
  36. file.managed:
  37. - name: /etc/salt/minion.d/_{{ name }}.conf
  38. - contents: |
  39. {{ conf|yaml(False)|indent(8) }}
  40. - require:
  41. - {{ minion.install_state }}
  42. salt_minion_config_{{ service_name }}_{{ name }}_validity_check:
  43. cmd.run:
  44. - name: python -c "import yaml; stream = file('/etc/salt/minion.d/_{{ name }}.conf', 'r'); yaml.load(stream); stream.close()"
  45. - onchanges:
  46. - file: salt_minion_config_{{ service_name }}_{{ name }}
  47. - onchanges_in:
  48. - cmd: salt_minion_service_restart
  49. {%- endfor %}
  50. {%- endif %}
  51. {%- if support_yaml %}
  52. {%- set dependency = support_yaml.get('dependency') %}
  53. {%- if dependency %}
  54. {%- if dependency.get('engine', 'pkg') == 'pkg' %}
  55. salt_minion_{{ service_name }}_dependencies:
  56. pkg.installed:
  57. - names: {{ dependency.get('pkgs') }}
  58. - onchanges_in:
  59. - cmd: salt_minion_service_restart
  60. {%- elif dependency.get('engine', 'pkg') == 'pip' %}
  61. {%- if dependency.get('pkgs') %}
  62. salt_minion_{{ service_name }}_dependencies:
  63. pkg.installed:
  64. - names: {{ dependency.get('pkgs') }}
  65. - onchanges_in:
  66. - cmd: salt_minion_service_restart
  67. - require_in:
  68. - pip: salt_minion_{{ service_name }}_dependencies_pip
  69. {%- endif %}
  70. salt_minion_{{ service_name }}_dependencies_pip:
  71. pip.installed:
  72. - names: {{ dependency.get('python_pkgs') }}
  73. - onchanges_in:
  74. - cmd: salt_minion_service_restart
  75. {%- endif %}
  76. {%- endif %}
  77. {%- endif %}
  78. {%- endfor %}
  79. {%- if renderer | length > 0 %}
  80. /etc/salt/minion.d/_renderer.conf:
  81. file.managed:
  82. - source: salt://salt/files/_renderer.conf
  83. - user: root
  84. - template: jinja
  85. - require:
  86. - {{ minion.install_state }}
  87. - watch_in:
  88. - service: salt_minion_service
  89. {%- endif %}
  90. salt_minion_service:
  91. service.running:
  92. - name: {{ minion.service }}
  93. - enable: true
  94. - require:
  95. - pkg: salt_minion_packages
  96. - pkg: salt_minion_dependency_packages
  97. {%- if grains.get('noservices') %}
  98. - onlyif: /bin/false
  99. {%- endif %}
  100. {#- Restart salt-minion if needed but after all states are executed #}
  101. salt_minion_service_restart:
  102. cmd.run:
  103. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  104. - shell: /bin/bash
  105. - bg: true
  106. - order: last
  107. - onchanges:
  108. - file: /etc/salt/minion.d/minion.conf
  109. {%- if grains.get('noservices') %}
  110. - onlyif: /bin/false
  111. {%- endif %}
  112. - require:
  113. - service: salt_minion_service
  114. salt_minion_sync_all:
  115. module.run:
  116. - name: 'saltutil.sync_all'
  117. - onchanges:
  118. - service: salt_minion_service
  119. - require:
  120. - pkg: salt_minion_packages
  121. - pkg: salt_minion_dependency_packages
  122. {%- endif %}