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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. {%- set processed_gitdirs = {} %}
  2. {%- set processed_gitdir_envs = [] %}
  3. {%- set processed_basedirs = [] %}
  4. {%- from "salt/map.jinja" import formulas_settings with context %}
  5. {%- from "salt/formulas.jinja" import formulas_git_opt with context %}
  6. {%- from "salt/formulas.jinja" import formulas_opts_for_git_latest with context %}
  7. ## from template-formula
  8. {%- set tplroot = tpldir.split('/')[0] %}
  9. {%- from tplroot ~ "/map.jinja" import salt_settings with context %}
  10. # Loop over all formulas listed in pillar data
  11. {%- for env, entries in salt['pillar.get']('salt_formulas:list', {}).items() %}
  12. {%- for entry in entries %}
  13. {%- set f_name = entry | first if entry is mapping else entry %}
  14. {%- set f_opts = entry[f_name] if entry is mapping else {} %}
  15. {%- set basedir = formulas_git_opt(env, 'basedir')|load_yaml %}
  16. {%- set gitdir = '{0}/{1}'.format(basedir, f_name) %}
  17. {%- set update = formulas_git_opt(env, 'update')|load_yaml %}
  18. {%- if formulas_settings.checkout_orig_branch %}
  19. {%- if not salt['file.directory_exists']('{0}/{1}'.format(gitdir, '.git')) %}
  20. {%- set gitdir_branch = '' %}
  21. {%- else %}
  22. {%- set gitdir_branch = salt['git.current_branch'](gitdir) %}
  23. {%- endif %}
  24. {%- do processed_gitdirs.update({gitdir:gitdir_branch}) %}
  25. {%- endif %}
  26. # Setup the directory hosting the Git repository
  27. {%- if basedir not in processed_basedirs %}
  28. {%- do processed_basedirs.append(basedir) %}
  29. {{ basedir }}:
  30. file.directory:
  31. - parallel: {{ salt_settings.parallel }}
  32. {%- for key, value in salt['pillar.get']('salt_formulas:basedir_opts',
  33. {'makedirs': True}).items() %}
  34. - {{ key }}: {{ value }}
  35. {%- endfor %}
  36. - user: {{ salt_settings.rootuser }}
  37. {%- if grains.kernel != 'Windows' %}
  38. - group: {{ salt_settings.rootgroup }}
  39. {%- endif %}
  40. {%- endif %}
  41. # Setup the formula Git repository
  42. {%- set gitdir_env = '{0}_{1}'.format(gitdir, env) %}
  43. {%- if gitdir_env not in processed_gitdir_envs %}
  44. {%- do processed_gitdir_envs.append(gitdir_env) %}
  45. {%- set options = formulas_opts_for_git_latest(env)|load_yaml %}
  46. {%- do options.update(f_opts) %}
  47. {%- set baseurl = formulas_git_opt(env, 'baseurl')|load_yaml %}
  48. {{ gitdir_env }}:
  49. git.latest:
  50. - name: {{ baseurl }}/{{ f_name }}.git
  51. - parallel: {{ salt_settings.parallel }}
  52. - target: {{ gitdir }}
  53. {%- for key, value in options.items() %}
  54. - {{ key }}: {{ value }}
  55. {%- endfor %}
  56. {%- if not update %}
  57. - unless: test -e {{ gitdir }} >/dev/null 2>&1
  58. {%- endif %}
  59. {%- endif %}
  60. {%- endfor %}
  61. {%- endfor %}
  62. {%- if formulas_settings.checkout_orig_branch %}
  63. # For each directory processed, explicitly checkout the original branch before
  64. # the `git.latest` state ran
  65. {%- for gitdir, original_branch in processed_gitdirs.items() %}
  66. {%- if original_branch %}
  67. {%- set gitdir_user = salt['file.get_user'](gitdir) %}
  68. checkout_original_branch_for_{{ gitdir }}:
  69. module.run:
  70. - name: git.checkout
  71. - order: last
  72. - cwd: {{ gitdir }}
  73. - rev: {{ original_branch }}
  74. - user: {{ gitdir_user }}
  75. - unless: test "$(cd {{ gitdir }}; git rev-parse --abbrev-ref HEAD)" = "{{ original_branch }}"
  76. {%- endif %}
  77. {%- endfor %}
  78. {%- endif %}