Saltstack Official Salt Formula
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

86 lines
3.3KB

  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.pkg.version_cmp(grains['saltversion'], '2017.7.0') >= 0 }}
  32. {%- for key, value in salt['pillar.get']('salt_formulas:basedir_opts',
  33. {'makedirs': True}).items() %}
  34. - {{ key }}: {{ value }}
  35. - user: {{ salt_settings.rootuser }}
  36. - group: {{ salt_settings.rootgroup }}
  37. {%- endfor %}
  38. {%- endif %}
  39. # Setup the formula Git repository
  40. {%- set gitdir_env = '{0}_{1}'.format(gitdir, env) %}
  41. {%- if gitdir_env not in processed_gitdir_envs %}
  42. {%- do processed_gitdir_envs.append(gitdir_env) %}
  43. {%- set options = formulas_opts_for_git_latest(env)|load_yaml %}
  44. {%- do options.update(f_opts) %}
  45. {%- set baseurl = formulas_git_opt(env, 'baseurl')|load_yaml %}
  46. {{ gitdir_env }}:
  47. git.latest:
  48. - name: {{ baseurl }}/{{ f_name }}.git
  49. - parallel: {{ salt.pkg.version_cmp(grains['saltversion'], '2017.7.0') >= 0 }}
  50. - target: {{ gitdir }}
  51. {%- for key, value in options.items() %}
  52. - {{ key }}: {{ value }}
  53. {%- endfor %}
  54. {%- if not update %}
  55. - unless: test -e {{ gitdir }} >/dev/null 2>&1
  56. {%- endif %}
  57. {%- endif %}
  58. {%- endfor %}
  59. {%- endfor %}
  60. {%- if formulas_settings.checkout_orig_branch %}
  61. # For each directory processed, explicitly checkout the original branch before
  62. # the `git.latest` state ran
  63. {%- for gitdir, original_branch in processed_gitdirs.items() %}
  64. {%- if original_branch %}
  65. {%- set gitdir_user = salt['file.get_user'](gitdir) %}
  66. checkout_original_branch_for_{{ gitdir }}:
  67. module.run:
  68. - name: git.checkout
  69. - order: last
  70. - cwd: {{ gitdir }}
  71. - rev: {{ original_branch }}
  72. - user: {{ gitdir_user }}
  73. - unless: test "$(cd {{ gitdir }}; git rev-parse --abbrev-ref HEAD)" = "{{ original_branch }}"
  74. {%- endif %}
  75. {%- endfor %}
  76. {%- endif %}