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

289 行
9.1KB

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