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.

100 lines
2.9KB

  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. 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. {%- endfor %}
  52. salt_minion_service:
  53. service.running:
  54. - name: {{ minion.service }}
  55. - enable: true
  56. - require:
  57. - pkg: salt_minion_packages
  58. - pkg: salt_minion_dependency_packages
  59. {%- if grains.get('noservices') %}
  60. - onlyif: /bin/false
  61. {%- endif %}
  62. {#- Restart salt-minion if needed but after all states are executed #}
  63. salt_minion_service_restart:
  64. cmd.run:
  65. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  66. - shell: /bin/bash
  67. - bg: true
  68. - order: last
  69. - onchanges:
  70. - file: /etc/salt/minion.d/minion.conf
  71. {%- if grains.get('noservices') %}
  72. - onlyif: /bin/false
  73. {%- endif %}
  74. - require:
  75. - service: salt_minion_service
  76. salt_minion_sync_all:
  77. module.run:
  78. - name: 'saltutil.sync_all'
  79. - onchanges:
  80. - service: salt_minion_service
  81. - require:
  82. - pkg: salt_minion_packages
  83. - pkg: salt_minion_dependency_packages
  84. {%- endif %}