New version of salt-formula from Saltstack
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

env.sls 11KB

il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 }}/_engines
  14. - /srv/salt/env/{{ master.system.environment }}
  15. - makedirs: True
  16. {%- for grain_name, grain in master.system.get('grain', {}).iteritems() %}
  17. {%- if grain.source == 'git' %}
  18. salt_master_{{ master.system.environment }}_{{ grain_name }}_grain_source:
  19. git.latest:
  20. - name: {{ grain.address }}
  21. - target: /srv/salt/env/{{ master.system.environment }}/_extra/grain_{{ grain_name }}
  22. - rev: {{ grain.revision }}
  23. - require:
  24. - file: salt_env_{{ master.system.environment }}_dirs
  25. - pkg: git_packages
  26. /srv/salt/env/{{ master.system.environment }}/_grains/{{ grain_name }}.py:
  27. file.symlink:
  28. - target: /srv/salt/env/{{ master.system.environment }}/_extra/grain_{{ grain_name }}/{{ grain_name }}.py
  29. - require:
  30. - git: salt_master_{{ master.system.environment }}_{{ grain_name }}_grain_source
  31. {%- endif %}
  32. {%- endfor %}
  33. {%- for state_name, state in master.system.get('state', {}).iteritems() %}
  34. {%- if state.source == 'git' %}
  35. salt_master_{{ master.system.environment }}_{{ state_name }}_state_source:
  36. git.latest:
  37. - name: {{ state.address }}
  38. - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}
  39. - rev: {{ state.revision }}
  40. - require:
  41. - file: salt_env_{{ master.system.environment }}_dirs
  42. - pkg: git_packages
  43. /srv/salt/env/{{ master.system.environment }}/_modules/{{ state_name }}.py:
  44. file.symlink:
  45. - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}/modules/{{ state_name }}.py
  46. - require:
  47. - git: salt_master_{{ master.system.environment }}_{{ state_name }}_state_source
  48. /srv/salt/env/{{ master.system.environment }}/_states/{{ state_name }}.py:
  49. file.symlink:
  50. - target: /srv/salt/env/{{ master.system.environment }}/_extra/state_{{ state_name }}/states/{{ state_name }}.py
  51. - require:
  52. - git: salt_master_{{ master.system.environment }}_{{ state_name }}_state_source
  53. {%- endif %}
  54. {%- endfor %}
  55. {%- for formula_name, formula in master.system.get('formula', {}).iteritems() %}
  56. {%- if formula.source == 'git' %}
  57. salt_master_{{ master.system.environment }}_{{ formula_name }}_formula_source:
  58. git.latest:
  59. - name: {{ formula.address }}
  60. - target: /srv/salt/env/{{ master.system.environment }}/{{ formula_name }}
  61. - rev: {{ formula.revision }}
  62. - require:
  63. - file: salt_env_{{ master.system.environment }}_dirs
  64. - pkg: git_packages
  65. {%- endif %}
  66. {%- endfor %}
  67. {%- if master.system.returners is defined %}
  68. salt_master_{{ master.system.environment }}_returners:
  69. git.latest:
  70. - name: {{ master.system.returners.address }}
  71. - target: /srv/salt/env/{{ master.system.environment }}/_returners
  72. - rev: {{ master.system.returners.revision }}
  73. - require:
  74. - file: salt_env_{{ master.system.environment }}_dirs
  75. - pkg: git_packages
  76. {%- endif %}
  77. {%- endif %}
  78. {# Start new #}
  79. {%- for environment_name, environment in master.get('environment', {}).iteritems() %}
  80. {%- if master.base_environment == environment_name %}
  81. salt_env_{{ environment_name }}_pre_dirs:
  82. file.directory:
  83. - names:
  84. - /usr/share/salt-formulas/env/_modules
  85. - /usr/share/salt-formulas/env/_states
  86. - /usr/share/salt-formulas/env/_grains
  87. - /usr/share/salt-formulas/env/_formulas
  88. - makedirs: True
  89. salt_env_{{ environment_name }}_dirs:
  90. file.symlink:
  91. - name: /srv/salt/env/{{ environment_name }}
  92. - target: /usr/share/salt-formulas/env
  93. - require:
  94. - file: salt_env_{{ environment_name }}_pre_dirs
  95. {%- else %}
  96. salt_env_{{ environment_name }}_dirs:
  97. file.directory:
  98. - names:
  99. - /srv/salt/env/{{ environment_name }}/_modules
  100. - /srv/salt/env/{{ environment_name }}/_states
  101. - /srv/salt/env/{{ environment_name }}/_grains
  102. - /srv/salt/env/{{ environment_name }}/_formulas
  103. - makedirs: True
  104. {%- endif %}
  105. {%- set _formula_pkgs = [] %}
  106. {%- set _formula_pkgs_with_version = [] %}
  107. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  108. {%- if formula.source == 'pkg' %}
  109. {%- if formula.version is defined %}
  110. {%- do _formula_pkgs_with_version.append(formula) %}
  111. {%- else %}
  112. {%- do _formula_pkgs.append(formula.name) %}
  113. {%- endif %}
  114. {%- endif %}
  115. {%- endfor %}
  116. {% if _formula_pkgs|length > 1 %}
  117. salt_master_{{ environment_name }}_pkg_formulas:
  118. pkg.latest:
  119. - pkgs:
  120. {%- for pkg in _formula_pkgs %}
  121. - {{ pkg }}
  122. {%- endfor %}
  123. - refresh: True
  124. - cache_valid_time: 300
  125. {% endif %}
  126. {% if _formula_pkgs_with_version|length > 1 %}
  127. {%- for formula in _formula_pkgs_with_version %}
  128. salt_master_{{ environment_name }}_pkg_formula_{{ formula.name }}:
  129. {%- if formula.version == 'latest' %}
  130. pkg.latest:
  131. - refresh: True
  132. - cache_valid_time: 300
  133. {%- elif formula.version == 'purged' %}
  134. pkg.purged:
  135. {%- elif formula.version == 'removed' %}
  136. pkg.removed:
  137. {%- else %}
  138. pkg.installed:
  139. - version: {{ formula.version }}
  140. - refresh: True
  141. - cache_valid_time: 300
  142. {% endif %}
  143. - name: {{ formula.name }}
  144. {%- endfor %}
  145. {% endif %}
  146. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  147. {%- if formula.source == 'git' %}
  148. {%- if master.base_environment == environment_name %}
  149. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  150. git.latest:
  151. - name: {{ formula.address }}
  152. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  153. {% if formula.get("revision", "").split("/")[0] == "refs" %}
  154. - rev: {{ formula.branch|default("master") }}
  155. {%- if grains['saltversion'] >= "2015.8.0" %}
  156. - branch: {{ formula.branch|default("master") }}
  157. {%- endif %}
  158. {% else %}
  159. - rev: {{ formula.revision|default(formula.branch) }}
  160. {%- if grains['saltversion'] >= "2015.8.0" %}
  161. - branch: {{ formula.branch|default(formula.revision) }}
  162. {%- endif %}
  163. {% endif %}
  164. - force_reset: {{ formula.force_reset|default(False) }}
  165. - require:
  166. - file: salt_env_{{ environment_name }}_dirs
  167. - pkg: git_packages
  168. {%- if formula.get("revision", "").split("/")[0] == "refs" %}
  169. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch:
  170. module.run:
  171. - name: git.fetch
  172. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  173. - opts: {{ formula.address }} {{ formula.revision }}
  174. - require:
  175. - git: salt_master_{{ environment_name }}_{{ formula_name }}_formula
  176. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset:
  177. module.run:
  178. - name: git.reset
  179. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  180. - opts: --hard FETCH_HEAD
  181. - require:
  182. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch
  183. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_rebase:
  184. module.run:
  185. - name: git.rebase
  186. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  187. - rev: origin/{{ formula.branch|default("master") }}
  188. - require:
  189. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset
  190. {%- endif %}
  191. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  192. file.symlink:
  193. - name: /usr/share/salt-formulas/env/{{ formula_name }}
  194. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/{{ formula_name }}
  195. - require:
  196. - file: salt_env_{{ environment_name }}_dirs
  197. - force: True
  198. - makedirs: True
  199. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  200. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  201. file.symlink:
  202. - name: /usr/share/salt-formulas/env/_grains/{{ grain_name }}
  203. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  204. - force: True
  205. - makedirs: True
  206. {%- endfor %}
  207. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  208. salt_master_{{ environment_name }}_{{ module_name }}_module:
  209. file.symlink:
  210. - name: /usr/share/salt-formulas/env/_modules/{{ module_name }}
  211. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_modules/{{ module_name }}
  212. - force: True
  213. - makedirs: True
  214. {%- endfor %}
  215. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  216. salt_master_{{ environment_name }}_{{ state_name }}_state:
  217. file.symlink:
  218. - name: /usr/share/salt-formulas/env/_states/{{ state_name }}
  219. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_states/{{ state_name }}
  220. - force: True
  221. - makedirs: True
  222. {%- endfor %}
  223. {%- else %}
  224. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  225. git.latest:
  226. - name: {{ formula.address }}
  227. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}
  228. - rev: {{ formula.revision }}
  229. - require:
  230. - file: salt_env_{{ environment_name }}_dirs
  231. - pkg: git_packages
  232. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  233. file.symlink:
  234. - name: /srv/salt/env/{{ environment_name }}/{{ formula_name }}
  235. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/{{ formula_name }}
  236. - require:
  237. - file: salt_env_{{ environment_name }}_dirs
  238. - force: True
  239. - makedirs: True
  240. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  241. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  242. file.symlink:
  243. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ grain_name }}
  244. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  245. - force: True
  246. - makedirs: True
  247. {%- endfor %}
  248. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  249. salt_master_{{ environment_name }}_{{ module_name }}_module:
  250. file.symlink:
  251. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ module_name }}
  252. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ module_name }}
  253. - force: True
  254. - makedirs: True
  255. {%- endfor %}
  256. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  257. salt_master_{{ environment_name }}_{{ state_name }}_state:
  258. file.symlink:
  259. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ state_name }}
  260. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ state_name }}
  261. - force: True
  262. - makedirs: True
  263. {%- endfor %}
  264. {%- for engine_name, engine in formula.get('engine', {}).iteritems() %}
  265. salt_master_{{ environment_name }}_{{ engine_name }}_state:
  266. file.symlink:
  267. - name: /srv/salt/env/{{ environment_name }}/_engines/{{ engine_name }}
  268. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_engines/{{ engine_name }}
  269. - force: True
  270. - makedirs: True
  271. {%- endfor %}
  272. {%- endif %}
  273. {%- endif %}
  274. {%- endfor %}
  275. {%- endfor %}
  276. {# end new #}
  277. {%- endif %}