New version of salt-formula from Saltstack
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

env.sls 9.2KB

9 lat temu
9 lat temu
9 lat temu
9 lat temu
9 lat temu
9 lat temu
9 lat temu
9 lat temu
9 lat temu
9 lat temu
9 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. {%- from "salt/map.jinja" import master with context %}
  2. {%- if master.enabled %}
  3. include:
  4. - git.client
  5. - salt.master.service
  6. {%- if master.system is defined %}
  7. salt_env_{{ master.system.environment }}_dirs_obsolete:
  8. file.directory:
  9. - names:
  10. - /srv/salt/env/{{ master.system.environment }}/_modules
  11. - /srv/salt/env/{{ master.system.environment }}/_states
  12. - /srv/salt/env/{{ master.system.environment }}/_grains
  13. - /srv/salt/env/{{ master.system.environment }}
  14. - makedirs: True
  15. {%- for grain_name, grain in master.system.get('grain', {}).iteritems() %}
  16. {%- if grain.source == 'git' %}
  17. salt_master_{{ master.system.environment }}_{{ grain_name }}_grain_source:
  18. git.latest:
  19. - name: {{ grain.address }}
  20. - target: /srv/salt/env/{{ master.system.environment }}/_extra/grain_{{ grain_name }}
  21. - rev: {{ grain.revision }}
  22. - require:
  23. - file: salt_env_{{ master.system.environment }}_dirs
  24. - pkg: git_packages
  25. /srv/salt/env/{{ master.system.environment }}/_grains/{{ grain_name }}.py:
  26. file.symlink:
  27. - target: /srv/salt/env/{{ master.system.environment }}/_extra/grain_{{ grain_name }}/{{ grain_name }}.py
  28. - require:
  29. - git: salt_master_{{ master.system.environment }}_{{ grain_name }}_grain_source
  30. {%- endif %}
  31. {%- endfor %}
  32. {%- for state_name, state in master.system.get('state', {}).iteritems() %}
  33. {%- if state.source == 'git' %}
  34. salt_master_{{ master.system.environment }}_{{ state_name }}_state_source:
  35. git.latest:
  36. - name: {{ state.address }}
  37. - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}
  38. - rev: {{ state.revision }}
  39. - require:
  40. - file: salt_env_{{ master.system.environment }}_dirs
  41. - pkg: git_packages
  42. /srv/salt/env/{{ master.system.environment }}/_modules/{{ state_name }}.py:
  43. file.symlink:
  44. - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}/modules/{{ state_name }}.py
  45. - require:
  46. - git: salt_master_{{ master.system.environment }}_{{ state_name }}_state_source
  47. /srv/salt/env/{{ master.system.environment }}/_states/{{ state_name }}.py:
  48. file.symlink:
  49. - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}/states/{{ state_name }}.py
  50. - require:
  51. - git: salt_master_{{ master.system.environment }}_{{ state_name }}_state_source
  52. {%- endif %}
  53. {%- endfor %}
  54. {%- for formula_name, formula in master.system.get('formula', {}).iteritems() %}
  55. {%- if formula.source == 'git' %}
  56. salt_master_{{ master.system.environment }}_{{ formula_name }}_formula_source:
  57. git.latest:
  58. - name: {{ formula.address }}
  59. - target: /srv/salt/env/{{ master.system.environment }}/{{ formula_name }}
  60. - rev: {{ formula.revision }}
  61. - require:
  62. - file: salt_env_{{ master.system.environment }}_dirs
  63. - pkg: git_packages
  64. {%- endif %}
  65. {%- endfor %}
  66. {%- if master.system.returners is defined %}
  67. salt_master_{{ master.system.environment }}_returners:
  68. git.latest:
  69. - name: {{ master.system.returners.address }}
  70. - target: /srv/salt/env/{{ master.system.environment }}/_returners
  71. - rev: {{ master.system.returners.revision }}
  72. - require:
  73. - file: salt_env_{{ master.system.environment }}_dirs
  74. - pkg: git_packages
  75. {%- endif %}
  76. {%- endif %}
  77. {# Start new #}
  78. {%- for environment_name, environment in master.get('environment', {}).iteritems() %}
  79. {%- if master.base_environment == environment_name %}
  80. salt_env_{{ environment_name }}_pre_dirs:
  81. file.directory:
  82. - names:
  83. - /usr/share/salt-formulas/env/_modules
  84. - /usr/share/salt-formulas/env/_states
  85. - /usr/share/salt-formulas/env/_grains
  86. - /usr/share/salt-formulas/env/_formulas
  87. - makedirs: True
  88. salt_env_{{ environment_name }}_dirs:
  89. file.symlink:
  90. - name: /srv/salt/env/{{ environment_name }}
  91. - target: /usr/share/salt-formulas/env
  92. - require:
  93. - file: salt_env_{{ environment_name }}_pre_dirs
  94. {%- else %}
  95. salt_env_{{ environment_name }}_dirs:
  96. file.directory:
  97. - names:
  98. - /srv/salt/env/{{ environment_name }}/_modules
  99. - /srv/salt/env/{{ environment_name }}/_states
  100. - /srv/salt/env/{{ environment_name }}/_grains
  101. - /srv/salt/env/{{ environment_name }}/_formulas
  102. - makedirs: True
  103. {%- endif %}
  104. salt_master_{{ environment_name }}_pkg_formulas:
  105. pkg.latest:
  106. - pkgs:
  107. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  108. {%- if formula.source == 'pkg' %}
  109. - {{ formula.name }}
  110. {%- endif %}
  111. {%- endfor %}
  112. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  113. {%- if formula.source == 'git' %}
  114. {%- if master.base_environment == environment_name %}
  115. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  116. git.latest:
  117. - name: {{ formula.address }}
  118. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  119. {% if formula.get("revision", "").split("/")[0] == "refs" %}
  120. - rev: {{ formula.branch|default("master") }}
  121. {%- if grains['saltversion'] >= "2015.8.0" %}
  122. - branch: {{ formula.branch|default("master") }}
  123. {%- endif %}
  124. {% else %}
  125. - rev: {{ formula.revision|default(formula.branch) }}
  126. {%- if grains['saltversion'] >= "2015.8.0" %}
  127. - branch: {{ formula.branch|default(formula.revision) }}
  128. {%- endif %}
  129. {% endif %}
  130. - force_reset: {{ formula.force_reset|default(False) }}
  131. - require:
  132. - file: salt_env_{{ environment_name }}_dirs
  133. - pkg: git_packages
  134. {%- if formula.get("revision", "").split("/")[0] == "refs" %}
  135. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch:
  136. module.run:
  137. - name: git.fetch
  138. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  139. - opts: {{ formula.address }} {{ formula.revision }}
  140. - require:
  141. - git: salt_master_{{ environment_name }}_{{ formula_name }}_formula
  142. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset:
  143. module.run:
  144. - name: git.reset
  145. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  146. - opts: --hard FETCH_HEAD
  147. - require:
  148. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch
  149. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_rebase:
  150. module.run:
  151. - name: git.rebase
  152. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  153. - rev: origin/{{ formula.branch|default("master") }}
  154. - require:
  155. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset
  156. {%- endif %}
  157. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  158. file.symlink:
  159. - name: /usr/share/salt-formulas/env/{{ formula_name }}
  160. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/{{ formula_name }}
  161. - require:
  162. - file: salt_env_{{ environment_name }}_dirs
  163. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  164. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  165. file.symlink:
  166. - name: /usr/share/salt-formulas/env/_grains/{{ grain_name }}
  167. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  168. {%- endfor %}
  169. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  170. salt_master_{{ environment_name }}_{{ module_name }}_module:
  171. file.symlink:
  172. - name: /usr/share/salt-formulas/env/_modules/{{ module_name }}
  173. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_modules/{{ module_name }}
  174. {%- endfor %}
  175. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  176. salt_master_{{ environment_name }}_{{ state_name }}_state:
  177. file.symlink:
  178. - name: /usr/share/salt-formulas/env/_states/{{ state_name }}
  179. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_states/{{ state_name }}
  180. {%- endfor %}
  181. {%- else %}
  182. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  183. git.latest:
  184. - name: {{ formula.address }}
  185. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}
  186. - rev: {{ formula.revision }}
  187. - require:
  188. - file: salt_env_{{ environment_name }}_dirs
  189. - pkg: git_packages
  190. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  191. file.symlink:
  192. - name: /srv/salt/env/{{ environment_name }}/{{ formula_name }}
  193. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/{{ formula_name }}
  194. - require:
  195. - file: salt_env_{{ environment_name }}_dirs
  196. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  197. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  198. file.symlink:
  199. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ grain_name }}
  200. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  201. {%- endfor %}
  202. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  203. salt_master_{{ environment_name }}_{{ module_name }}_module:
  204. file.symlink:
  205. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ module_name }}
  206. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ module_name }}
  207. {%- endfor %}
  208. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  209. salt_master_{{ environment_name }}_{{ state_name }}_state:
  210. file.symlink:
  211. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ state_name }}
  212. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ state_name }}
  213. {%- endfor %}
  214. {%- endif %}
  215. {%- endif %}
  216. {%- endfor %}
  217. {%- endfor %}
  218. {# end new #}
  219. {%- endif %}