New version of salt-formula from Saltstack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.7KB

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