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.

344 lines
10KB

  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. - force: True
  197. - makedirs: True
  198. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  199. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  200. file.symlink:
  201. - name: /usr/share/salt-formulas/env/_grains/{{ grain_name }}
  202. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  203. - force: True
  204. - makedirs: True
  205. {%- endfor %}
  206. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  207. salt_master_{{ environment_name }}_{{ module_name }}_module:
  208. file.symlink:
  209. - name: /usr/share/salt-formulas/env/_modules/{{ module_name }}
  210. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_modules/{{ module_name }}
  211. - force: True
  212. - makedirs: True
  213. {%- endfor %}
  214. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  215. salt_master_{{ environment_name }}_{{ state_name }}_state:
  216. file.symlink:
  217. - name: /usr/share/salt-formulas/env/_states/{{ state_name }}
  218. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_states/{{ state_name }}
  219. - force: True
  220. - makedirs: True
  221. {%- endfor %}
  222. {%- else %}
  223. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  224. git.latest:
  225. - name: {{ formula.address }}
  226. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}
  227. - rev: {{ formula.revision }}
  228. - require:
  229. - file: salt_env_{{ environment_name }}_dirs
  230. - pkg: git_packages
  231. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  232. file.symlink:
  233. - name: /srv/salt/env/{{ environment_name }}/{{ formula_name }}
  234. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/{{ formula_name }}
  235. - require:
  236. - file: salt_env_{{ environment_name }}_dirs
  237. - force: True
  238. - makedirs: True
  239. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  240. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  241. file.symlink:
  242. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ grain_name }}
  243. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  244. - force: True
  245. - makedirs: True
  246. {%- endfor %}
  247. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  248. salt_master_{{ environment_name }}_{{ module_name }}_module:
  249. file.symlink:
  250. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ module_name }}
  251. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ module_name }}
  252. - force: True
  253. - makedirs: True
  254. {%- endfor %}
  255. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  256. salt_master_{{ environment_name }}_{{ state_name }}_state:
  257. file.symlink:
  258. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ state_name }}
  259. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ state_name }}
  260. - force: True
  261. - makedirs: True
  262. {%- endfor %}
  263. {%- endif %}
  264. {%- endif %}
  265. {%- endfor %}
  266. {%- endfor %}
  267. {# end new #}
  268. {%- endif %}