New version of salt-formula from Saltstack
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

128 lines
3.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.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. {%- if support_yaml and support_yaml.get('dependency', {}) %}
  52. {%- if support_yaml.get('engine', 'pkg') == 'pkg' %}
  53. salt_minion_{{ service_name }}_dependencies:
  54. pkg.installed:
  55. - names: {{ support_yaml.pkgs }}
  56. - onchanges_in:
  57. - cmd: salt_minion_service_restart
  58. {%- elif support_yaml.engine == 'pip' %}
  59. {%- if support_yaml.get('pkgs') %}
  60. salt_minion_{{ service_name }}_dependencies:
  61. pip.installed:
  62. - names: {{ support_yaml.pkgs }}
  63. - onchanges_in:
  64. - cmd: salt_minion_service_restart
  65. - require_in:
  66. - pip: salt_minion_{{ service_name }}_dependencies_pip
  67. {%- endif %}
  68. salt_minion_{{ service_name }}_dependencies_pip:
  69. pip.installed:
  70. - names: {{ support_yaml.python_pkgs }}
  71. - onchanges_in:
  72. - cmd: salt_minion_service_restart
  73. {%- endif %}
  74. {%- endif %}
  75. {%- endfor %}
  76. salt_minion_service:
  77. service.running:
  78. - name: {{ minion.service }}
  79. - enable: true
  80. - require:
  81. - pkg: salt_minion_packages
  82. - pkg: salt_minion_dependency_packages
  83. {%- if grains.get('noservices') %}
  84. - onlyif: /bin/false
  85. {%- endif %}
  86. {#- Restart salt-minion if needed but after all states are executed #}
  87. salt_minion_service_restart:
  88. cmd.run:
  89. - name: 'while true; do salt-call saltutil.running|grep fun: && continue; salt-call --local service.restart {{ minion.service }}; break; done'
  90. - shell: /bin/bash
  91. - bg: true
  92. - order: last
  93. - onchanges:
  94. - file: /etc/salt/minion.d/minion.conf
  95. {%- if grains.get('noservices') %}
  96. - onlyif: /bin/false
  97. {%- endif %}
  98. - require:
  99. - service: salt_minion_service
  100. salt_minion_sync_all:
  101. module.run:
  102. - name: 'saltutil.sync_all'
  103. - onchanges:
  104. - service: salt_minion_service
  105. - require:
  106. - pkg: salt_minion_packages
  107. - pkg: salt_minion_dependency_packages
  108. {%- endif %}