New version of salt-formula from Saltstack
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

service.sls 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. - watch_in:
  24. - service: salt_minion_service
  25. {%- for service_name, service in pillar.items() %}
  26. {%- set support_fragment_file = service_name+'/meta/salt.yml' %}
  27. {%- macro load_support_file() %}{% include support_fragment_file ignore missing %}{% endmacro %}
  28. {%- set support_yaml = load_support_file()|load_yaml %}
  29. {%- if support_yaml and support_yaml.get('minion', {}) %}
  30. {%- for name, conf in support_yaml.get('minion', {}).iteritems() %}
  31. salt_minion_config_{{ service_name }}_{{ name }}:
  32. file.managed:
  33. - name: /etc/salt/minion.d/_{{ name }}.conf
  34. - contents: |
  35. {{ conf|yaml(False)|indent(8) }}
  36. - watch_in:
  37. - cmd: salt_minion_service_restart
  38. - require:
  39. - {{ minion.install_state }}
  40. salt_minion_config_{{ service_name }}_{{ name }}_validity_check:
  41. cmd.wait:
  42. - name: python -c "import yaml; stream = file('/etc/salt/minion.d/_{{ name }}.conf', 'r'); yaml.load(stream); stream.close()"
  43. - watch:
  44. - file: salt_minion_config_{{ service_name }}_{{ name }}
  45. - require_in:
  46. - cmd: salt_minion_service_restart
  47. {%- endfor %}
  48. {%- endif %}
  49. {%- endfor %}
  50. salt_minion_service:
  51. service.running:
  52. - name: {{ minion.service }}
  53. - enable: true
  54. {%- if grains.get('noservices') %}
  55. - onlyif: /bin/false
  56. {%- endif %}
  57. {#- Restart salt-minion if needed but after all states are executed #}
  58. salt_minion_service_restart:
  59. cmd.wait:
  60. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  61. - shell: /bin/bash
  62. - bg: true
  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. - watch:
  72. - service: salt_minion_service
  73. {%- endif %}