New version of salt-formula from Saltstack
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. - /usr/share/salt-formulas/env/_engines
  89. - /usr/share/salt-formulas/env/_runners
  90. - makedirs: True
  91. salt_env_{{ environment_name }}_dirs:
  92. file.symlink:
  93. - name: /srv/salt/env/{{ environment_name }}
  94. - target: /usr/share/salt-formulas/env
  95. - require:
  96. - file: salt_env_{{ environment_name }}_pre_dirs
  97. {%- else %}
  98. salt_env_{{ environment_name }}_dirs:
  99. file.directory:
  100. - names:
  101. - /srv/salt/env/{{ environment_name }}/_modules
  102. - /srv/salt/env/{{ environment_name }}/_states
  103. - /srv/salt/env/{{ environment_name }}/_grains
  104. - /srv/salt/env/{{ environment_name }}/_formulas
  105. - /srv/salt/env/{{ environment_name }}/_engines
  106. - /srv/salt/env/{{ environment_name }}/_runners
  107. - makedirs: True
  108. {%- endif %}
  109. {%- set _formula_pkgs = [] %}
  110. {%- set _formula_pkgs_with_version = [] %}
  111. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  112. {%- if formula.source == 'pkg' %}
  113. {%- if formula.version is defined %}
  114. {%- do _formula_pkgs_with_version.append(formula) %}
  115. {%- else %}
  116. {%- do _formula_pkgs.append(formula.name) %}
  117. {%- endif %}
  118. {%- endif %}
  119. {%- endfor %}
  120. {% if _formula_pkgs|length > 1 %}
  121. salt_master_{{ environment_name }}_pkg_formulas:
  122. pkg.latest:
  123. - pkgs:
  124. {%- for pkg in _formula_pkgs %}
  125. - {{ pkg }}
  126. {%- endfor %}
  127. - refresh: True
  128. - cache_valid_time: 300
  129. {% endif %}
  130. {% if _formula_pkgs_with_version|length > 1 %}
  131. {%- for formula in _formula_pkgs_with_version %}
  132. salt_master_{{ environment_name }}_pkg_formula_{{ formula.name }}:
  133. {%- if formula.version == 'latest' %}
  134. pkg.latest:
  135. - refresh: True
  136. - cache_valid_time: 300
  137. {%- elif formula.version == 'purged' %}
  138. pkg.purged:
  139. {%- elif formula.version == 'removed' %}
  140. pkg.removed:
  141. {%- else %}
  142. pkg.installed:
  143. - version: {{ formula.version }}
  144. - refresh: True
  145. - cache_valid_time: 300
  146. {% endif %}
  147. - name: {{ formula.name }}
  148. {%- endfor %}
  149. {% endif %}
  150. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  151. {%- if formula.source == 'git' %}
  152. {%- if master.base_environment == environment_name %}
  153. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  154. git.latest:
  155. - name: {{ formula.address }}
  156. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  157. {% if formula.get("revision", "").split("/")[0] == "refs" %}
  158. - rev: {{ formula.branch|default("master") }}
  159. {%- if grains['saltversion'] >= "2015.8.0" %}
  160. - branch: {{ formula.branch|default("master") }}
  161. {%- endif %}
  162. {% else %}
  163. - rev: {{ formula.revision|default(formula.branch) }}
  164. {%- if grains['saltversion'] >= "2015.8.0" %}
  165. - branch: {{ formula.branch|default(formula.revision) }}
  166. {%- endif %}
  167. {% endif %}
  168. - submodules: {{ formula.submodules|default(False) }}
  169. - force_reset: {{ formula.force_reset|default(False) }}
  170. - require:
  171. - file: salt_env_{{ environment_name }}_dirs
  172. - pkg: git_packages
  173. {%- if formula.get("revision", "").split("/")[0] == "refs" %}
  174. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch:
  175. module.run:
  176. - name: git.fetch
  177. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  178. - opts: {{ formula.address }} {{ formula.revision }}
  179. - require:
  180. - git: salt_master_{{ environment_name }}_{{ formula_name }}_formula
  181. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset:
  182. module.run:
  183. - name: git.reset
  184. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  185. - opts: --hard FETCH_HEAD
  186. - require:
  187. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch
  188. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_rebase:
  189. module.run:
  190. - name: git.rebase
  191. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  192. - rev: origin/{{ formula.branch|default("master") }}
  193. - require:
  194. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset
  195. {%- endif %}
  196. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  197. file.symlink:
  198. - name: /usr/share/salt-formulas/env/{{ formula_name }}
  199. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/{{ formula_name }}
  200. - require:
  201. - file: salt_env_{{ environment_name }}_dirs
  202. - force: True
  203. - makedirs: True
  204. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  205. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  206. file.symlink:
  207. - name: /usr/share/salt-formulas/env/_grains/{{ grain_name }}
  208. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  209. - force: True
  210. - makedirs: True
  211. {%- endfor %}
  212. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  213. salt_master_{{ environment_name }}_{{ module_name }}_module:
  214. file.symlink:
  215. - name: /usr/share/salt-formulas/env/_modules/{{ module_name }}
  216. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_modules/{{ module_name }}
  217. - force: True
  218. - makedirs: True
  219. {%- endfor %}
  220. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  221. salt_master_{{ environment_name }}_{{ state_name }}_state:
  222. file.symlink:
  223. - name: /usr/share/salt-formulas/env/_states/{{ state_name }}
  224. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_states/{{ state_name }}
  225. - force: True
  226. - makedirs: True
  227. {%- endfor %}
  228. {%- else %}
  229. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  230. git.latest:
  231. - name: {{ formula.address }}
  232. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}
  233. - rev: {{ formula.revision }}
  234. - require:
  235. - file: salt_env_{{ environment_name }}_dirs
  236. - pkg: git_packages
  237. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  238. file.symlink:
  239. - name: /srv/salt/env/{{ environment_name }}/{{ formula_name }}
  240. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/{{ formula_name }}
  241. - require:
  242. - file: salt_env_{{ environment_name }}_dirs
  243. - force: True
  244. - makedirs: True
  245. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  246. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  247. file.symlink:
  248. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ grain_name }}
  249. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  250. - force: True
  251. - makedirs: True
  252. {%- endfor %}
  253. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  254. salt_master_{{ environment_name }}_{{ module_name }}_module:
  255. file.symlink:
  256. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ module_name }}
  257. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ module_name }}
  258. - force: True
  259. - makedirs: True
  260. {%- endfor %}
  261. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  262. salt_master_{{ environment_name }}_{{ state_name }}_state:
  263. file.symlink:
  264. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ state_name }}
  265. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ state_name }}
  266. - force: True
  267. - makedirs: True
  268. {%- endfor %}
  269. {%- for engine_name, engine in formula.get('engine', {}).iteritems() %}
  270. salt_master_{{ environment_name }}_{{ engine_name }}_engine:
  271. file.symlink:
  272. - name: /srv/salt/env/{{ environment_name }}/_engines/{{ engine_name }}
  273. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_engines/{{ engine_name }}
  274. - force: True
  275. - makedirs: True
  276. {%- endfor %}
  277. {%- for runner_name, runner in formula.get('runner', {}).iteritems() %}
  278. salt_master_{{ environment_name }}_{{ runner_name }}_runner:
  279. file.symlink:
  280. - name: /srv/salt/env/{{ environment_name }}/_engines/{{ runner_name }}
  281. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_engines/{{ runner_name }}
  282. - force: True
  283. - makedirs: True
  284. {%- endfor %}
  285. {%- endif %}
  286. {%- endif %}
  287. {%- endfor %}
  288. {%- endfor %}
  289. {# end new #}
  290. {%- endif %}