New version of salt-formula from Saltstack
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

301 行
9.3KB

  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. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  106. {%- if formula.source == 'pkg' %}
  107. {%- do _formula_pkgs.append(formula.name) %}
  108. {%- endif %}
  109. {%- endfor %}
  110. {% if _formula_pkgs|length > 1 %}
  111. salt_master_{{ environment_name }}_pkg_formulas:
  112. pkg.latest:
  113. - pkgs:
  114. {%- for pkg in _formula_pkgs %}
  115. - {{ pkg }}
  116. {%- endfor %}
  117. {% endif %}
  118. {%- for formula_name, formula in environment.get('formula', {}).iteritems() %}
  119. {%- if formula.source == 'git' %}
  120. {%- if master.base_environment == environment_name %}
  121. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  122. git.latest:
  123. - name: {{ formula.address }}
  124. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  125. {% if formula.get("revision", "").split("/")[0] == "refs" %}
  126. - rev: {{ formula.branch|default("master") }}
  127. {%- if grains['saltversion'] >= "2015.8.0" %}
  128. - branch: {{ formula.branch|default("master") }}
  129. {%- endif %}
  130. {% else %}
  131. - rev: {{ formula.revision|default(formula.branch) }}
  132. {%- if grains['saltversion'] >= "2015.8.0" %}
  133. - branch: {{ formula.branch|default(formula.revision) }}
  134. {%- endif %}
  135. {% endif %}
  136. - force_reset: {{ formula.force_reset|default(False) }}
  137. - require:
  138. - file: salt_env_{{ environment_name }}_dirs
  139. - pkg: git_packages
  140. {%- if formula.get("revision", "").split("/")[0] == "refs" %}
  141. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch:
  142. module.run:
  143. - name: git.fetch
  144. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  145. - opts: {{ formula.address }} {{ formula.revision }}
  146. - require:
  147. - git: salt_master_{{ environment_name }}_{{ formula_name }}_formula
  148. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset:
  149. module.run:
  150. - name: git.reset
  151. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  152. - opts: --hard FETCH_HEAD
  153. - require:
  154. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_fetch
  155. salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_rebase:
  156. module.run:
  157. - name: git.rebase
  158. - cwd: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}
  159. - rev: origin/{{ formula.branch|default("master") }}
  160. - require:
  161. - module: salt_master_{{ environment_name }}_{{ formula_name }}_formula_refs_workaround_reset
  162. {%- endif %}
  163. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  164. file.symlink:
  165. - name: /usr/share/salt-formulas/env/{{ formula_name }}
  166. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/{{ formula_name }}
  167. - require:
  168. - file: salt_env_{{ environment_name }}_dirs
  169. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  170. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  171. file.symlink:
  172. - name: /usr/share/salt-formulas/env/_grains/{{ grain_name }}
  173. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  174. {%- endfor %}
  175. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  176. salt_master_{{ environment_name }}_{{ module_name }}_module:
  177. file.symlink:
  178. - name: /usr/share/salt-formulas/env/_modules/{{ module_name }}
  179. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_modules/{{ module_name }}
  180. {%- endfor %}
  181. {%- for state_name, state in formula.get('state', {}).iteritems() %}
  182. salt_master_{{ environment_name }}_{{ state_name }}_state:
  183. file.symlink:
  184. - name: /usr/share/salt-formulas/env/_states/{{ state_name }}
  185. - target: /usr/share/salt-formulas/env/_formulas/{{ formula_name }}/_states/{{ state_name }}
  186. {%- endfor %}
  187. {%- else %}
  188. salt_master_{{ environment_name }}_{{ formula_name }}_formula:
  189. git.latest:
  190. - name: {{ formula.address }}
  191. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}
  192. - rev: {{ formula.revision }}
  193. - require:
  194. - file: salt_env_{{ environment_name }}_dirs
  195. - pkg: git_packages
  196. salt_env_{{ environment_name }}_{{ formula_name }}_link:
  197. file.symlink:
  198. - name: /srv/salt/env/{{ environment_name }}/{{ formula_name }}
  199. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/{{ formula_name }}
  200. - require:
  201. - file: salt_env_{{ environment_name }}_dirs
  202. {%- for grain_name, grain in formula.get('grain', {}).iteritems() %}
  203. salt_master_{{ environment_name }}_{{ grain_name }}_grain:
  204. file.symlink:
  205. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ grain_name }}
  206. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ grain_name }}
  207. {%- endfor %}
  208. {%- for module_name, module in formula.get('module', {}).iteritems() %}
  209. salt_master_{{ environment_name }}_{{ module_name }}_module:
  210. file.symlink:
  211. - name: /srv/salt/env/{{ environment_name }}/_grains/{{ module_name }}
  212. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ module_name }}
  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: /srv/salt/env/{{ environment_name }}/_grains/{{ state_name }}
  218. - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_grains/{{ state_name }}
  219. {%- endfor %}
  220. {%- endif %}
  221. {%- endif %}
  222. {%- endfor %}
  223. {%- endfor %}
  224. {# end new #}
  225. {%- endif %}