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.

env.sls 10KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. {%- set _formula_pkgs = [] %}
  105. {%- set _formula_pkgs_with_version = [] %}
  106. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  107. {%- if formula.source == 'pkg' %}
  108. {%- if formula.version is defined %}
  109. {%- do _formula_pkgs_with_version.append(formula) %}
  110. {%- else %}
  111. {%- do _formula_pkgs.append(formula.name) %}
  112. {%- endif %}
  113. {%- endif %}
  114. {%- endfor %}
  115. {% if _formula_pkgs|length > 1 %}
  116. salt_master_{{ environment_name }}_pkg_formulas:
  117. pkg.latest:
  118. - pkgs:
  119. {%- for pkg in _formula_pkgs %}
  120. - {{ pkg }}
  121. {%- endfor %}
  122. - refresh: True
  123. - cache_valid_time: 300
  124. {% endif %}
  125. {% if _formula_pkgs_with_version|length > 1 %}
  126. {%- for formula in _formula_pkgs_with_version %}
  127. salt_master_{{ environment_name }}_pkg_formula_{{ formula.name }}:
  128. {%- if formula.version == 'latest' %}
  129. pkg.latest:
  130. - refresh: True
  131. - cache_valid_time: 300
  132. {%- elif formula.version == 'purged' %}
  133. pkg.purged:
  134. {%- elif formula.version == 'removed' %}
  135. pkg.removed:
  136. {%- else %}
  137. pkg.installed:
  138. - version: {{ formula.version }}
  139. - refresh: True
  140. - cache_valid_time: 300
  141. {% endif %}
  142. - name: {{ formula.name }}
  143. {%- endfor %}
  144. {% endif %}
  145. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  146. {%- if formula.source == 'git' %}
  147. {%- if master.base_environment == environment_name %}
  148. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  149. git.latest:
  150. - name: {{ formula.address }}
  151. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  152. {% if formula.get("revision", "").split("/")[0] == "refs" %}
  153. - rev: {{ formula.branch|default("master") }}
  154. {%- if grains['saltversion'] >= "2015.8.0" %}
  155. - branch: {{ formula.branch|default("master") }}
  156. {%- endif %}
  157. {% else %}
  158. - rev: {{ formula.revision|default(formula.branch) }}
  159. {%- if grains['saltversion'] >= "2015.8.0" %}
  160. - branch: {{ formula.branch|default(formula.revision) }}
  161. {%- endif %}
  162. {% endif %}
  163. - force_reset: {{ formula.force_reset|default(False) }}
  164. - require:
  165. - file: salt_env_{{ environment_name }}_dirs
  166. - pkg: git_packages
  167. {%- if formula.get("revision", "").split("/")[0] == "refs" %}
  168. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch:
  169. module.run:
  170. - name: git.fetch
  171. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  172. - opts: {{ formula.address }} {{ formula.revision }}
  173. - require:
  174. - git: salt_master_{{ environment_name }}_{{ formula_name }}_formula
  175. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset:
  176. module.run:
  177. - name: git.reset
  178. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  179. - opts: --hard FETCH_HEAD
  180. - require:
  181. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch
  182. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_rebase:
  183. module.run:
  184. - name: git.rebase
  185. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  186. - rev: origin/{{ formula.branch|default("master") }}
  187. - require:
  188. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset
  189. {%- endif %}
  190. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  191. file.symlink:
  192. - name: /usr/share/salt-formulas/env/{{ formula_name }}
  193. - target: /usr/share/salt-formulas/env/_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: /usr/share/salt-formulas/env/_grains/{{ grain_name }}
  200. - target: /usr/share/salt-formulas/env/_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: /usr/share/salt-formulas/env/_modules/{{ module_name }}
  206. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_modules/{{ 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: /usr/share/salt-formulas/env/_states/{{ state_name }}
  212. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_states/{{ state_name }}
  213. {%- endfor %}
  214. {%- else %}
  215. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  216. git.latest:
  217. - name: {{ formula.address }}
  218. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}
  219. - rev: {{ formula.revision }}
  220. - require:
  221. - file: salt_env_{{ environment_name }}_dirs
  222. - pkg: git_packages
  223. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  224. file.symlink:
  225. - name: /srv/salt/env/{{ environment_name }}/{{ formula_name }}
  226. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/{{ formula_name }}
  227. - require:
  228. - file: salt_env_{{ environment_name }}_dirs
  229. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  230. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  231. file.symlink:
  232. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ grain_name }}
  233. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  234. {%- endfor %}
  235. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  236. salt_master_{{ environment_name }}_{{ module_name }}_module:
  237. file.symlink:
  238. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ module_name }}
  239. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ module_name }}
  240. {%- endfor %}
  241. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  242. salt_master_{{ environment_name }}_{{ state_name }}_state:
  243. file.symlink:
  244. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ state_name }}
  245. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ state_name }}
  246. {%- endfor %}
  247. {%- endif %}
  248. {%- endif %}
  249. {%- endfor %}
  250. {%- endfor %}
  251. {# end new #}
  252. {%- endif %}