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ů.

86 lines
2.5KB

  1. {%- from "salt/map.jinja" import minion 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. {%- elif minion.source.get('engine', 'pkg') == 'pip' %}
  11. salt_minion_packages:
  12. pip.installed:
  13. - name: salt{% if minion.source.version is defined %}=={{ minion.source.version }}{% endif %}
  14. {%- endif %}
  15. /etc/salt/minion.d/minion.conf:
  16. file.managed:
  17. - source: salt://salt/files/minion.conf
  18. - user: root
  19. - group: root
  20. - template: jinja
  21. - require:
  22. - {{ minion.install_state }}
  23. {%- for service_name, service in pillar.items() %}
  24. {%- set support_fragment_file = service_name+'/meta/salt.yml' %}
  25. {%- macro load_support_file() %}{% include support_fragment_file ignore missing %}{% endmacro %}
  26. {%- set support_yaml = load_support_file()|load_yaml %}
  27. {%- if support_yaml and support_yaml.get('minion', {}) %}
  28. {%- for name, conf in support_yaml.get('minion', {}).iteritems() %}
  29. salt_minion_config_{{ service_name }}_{{ name }}:
  30. file.managed:
  31. - name: /etc/salt/minion.d/_{{ name }}.conf
  32. - contents: |
  33. {{ conf|yaml(False)|indent(8) }}
  34. - require:
  35. - {{ minion.install_state }}
  36. salt_minion_config_{{ service_name }}_{{ name }}_validity_check:
  37. cmd.run:
  38. - name: python -c "import yaml; stream = file('/etc/salt/minion.d/_{{ name }}.conf', 'r'); yaml.load(stream); stream.close()"
  39. - onchanges:
  40. - file: salt_minion_config_{{ service_name }}_{{ name }}
  41. - onchanges_in:
  42. - cmd: salt_minion_service_restart
  43. {%- endfor %}
  44. {%- endif %}
  45. {%- endfor %}
  46. salt_minion_service:
  47. service.running:
  48. - name: {{ minion.service }}
  49. - enable: true
  50. {%- if grains.get('noservices') %}
  51. - onlyif: /bin/false
  52. {%- endif %}
  53. {#- Restart salt-minion if needed but after all states are executed #}
  54. salt_minion_service_restart:
  55. cmd.run:
  56. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  57. - shell: /bin/bash
  58. - bg: true
  59. - order: last
  60. - onchanges:
  61. - file: /etc/salt/minion.d/minion.conf
  62. {%- if grains.get('noservices') %}
  63. - onlyif: /bin/false
  64. {%- endif %}
  65. - require:
  66. - service: salt_minion_service
  67. salt_minion_sync_all:
  68. module.run:
  69. - name: 'saltutil.sync_all'
  70. - onchanges:
  71. - service: salt_minion_service
  72. {%- endif %}