New version of salt-formula from Saltstack
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

service.sls 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.latest:
  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. {%- if not grains.get('noservices', False) %}
  30. - watch_in:
  31. - service: salt_minion_service
  32. {%- endif %}
  33. {%- for service_name, service in pillar.items() %}
  34. {%- set support_fragment_file = service_name+'/meta/salt.yml' %}
  35. {%- macro load_support_file() %}{% include support_fragment_file ignore missing %}{% endmacro %}
  36. {%- set support_yaml = load_support_file()|load_yaml %}
  37. {%- if support_yaml and support_yaml.get('minion', {}) %}
  38. {%- for name, conf in support_yaml.get('minion', {}).iteritems() %}
  39. salt_minion_config_{{ service_name }}_{{ name }}:
  40. file.managed:
  41. - name: /etc/salt/minion.d/_{{ name }}.conf
  42. - contents: |
  43. {{ conf|yaml(False)|indent(8) }}
  44. {%- if not grains.get('noservices', False) %}
  45. - watch_in:
  46. - cmd: salt_minion_service_restart
  47. {%- endif %}
  48. - require:
  49. - {{ minion.install_state }}
  50. salt_minion_config_{{ service_name }}_{{ name }}_validity_check:
  51. cmd.wait:
  52. - name: python -c "import yaml; stream = file('/etc/salt/minion.d/_{{ name }}.conf', 'r'); yaml.load(stream); stream.close()"
  53. - watch:
  54. - file: salt_minion_config_{{ service_name }}_{{ name }}
  55. {%- if not grains.get('noservices', False) %}
  56. - require_in:
  57. - cmd: salt_minion_service_restart
  58. {%- endif %}
  59. {%- endfor %}
  60. {%- endif %}
  61. {%- endfor %}
  62. {%- if not grains.get('noservices', False) %}
  63. salt_minion_service:
  64. service.running:
  65. - name: {{ minion.service }}
  66. - enable: true
  67. - require:
  68. - pkg: salt_minion_packages
  69. - pkg: salt_minion_dependency_packages
  70. {#- Restart salt-minion if needed but after all states are executed #}
  71. salt_minion_service_restart:
  72. cmd.wait:
  73. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  74. - shell: /bin/bash
  75. - bg: true
  76. - require:
  77. - service: salt_minion_service
  78. {%- endif %}
  79. salt_minion_sync_all:
  80. module.run:
  81. - name: 'saltutil.sync_all'
  82. {%- if not grains.get('noservices', False) %}
  83. - watch:
  84. - service: salt_minion_service
  85. {%- endif %}
  86. - require:
  87. - pkg: salt_minion_packages
  88. - pkg: salt_minion_dependency_packages
  89. {%- endif %}