Saltstack Official Users Formula
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

63 lines
2.4KB

  1. {% from "users/map.jinja" import users with context -%}
  2. include:
  3. - users
  4. {% set userfile_dirs = salt['cp.list_master_dirs'](prefix='users/files/user/') -%}
  5. {%- for username, user in salt['pillar.get']('users', {}).items() if (user.absent is not defined or not user.absent) -%}
  6. {%- set current = salt.user.info(username) -%}
  7. {%- set user_files = salt['pillar.get'](('users:' ~ username ~ ':user_files'), {'enabled': False}) -%}
  8. {%- set user_group = salt['pillar.get'](('users:' ~ username ~ ':prime_group:name'), username) -%}
  9. {%- set user_home = salt['pillar.get'](('users:' ~ username ~ ':home'), current.get('home', '/home/' ~ username )) -%}
  10. {%- set user_files_template = salt['pillar.get'](('users:' ~ username ~ ':user_files:template'), None) -%}
  11. {%- set user_files_file_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:file_mode'), False) -%}
  12. {%- set user_files_sym_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:sym_mode'), False) -%}
  13. {%- set user_files_exclude_pat = salt['pillar.get'](('users:' ~ username ~ ':user_files:exclude_pat'), False) -%}
  14. {%- if user_files.enabled -%}
  15. {%- if user_files.source is defined -%}
  16. {%- if user_files.source.startswith('salt://') -%}
  17. {%- set file_source = user_files.source -%}
  18. {%- else -%}
  19. {%- set file_source = ('salt://' ~ user.user_files.source) -%}
  20. {%- endif -%}
  21. {%- set skip_user = False -%}
  22. {%- else -%}
  23. {%- if ('users/files/user/' ~ username) in userfile_dirs -%}
  24. {%- set file_source = ('salt://users/files/user/' ~ username) -%}
  25. {%- set skip_user = False -%}
  26. {%- else -%}
  27. {%- set skip_user = True -%}
  28. {%- endif -%}
  29. {%- endif -%}
  30. {%- if not skip_user %}
  31. users_userfiles_{{ username }}_recursive:
  32. file.recurse:
  33. - name: {{ user_home }}
  34. - source: {{ file_source }}
  35. - user: {{ username }}
  36. - group: {{ user_group }}
  37. {% if user_files_template -%}
  38. - template: {{ user_files_template }}
  39. {% endif -%}
  40. - clean: False
  41. {% if user_files_file_mode -%}
  42. - file_mode: {{ user_files_file_mode }}
  43. {% endif -%}
  44. {% if user_files_sym_mode -%}
  45. - sym_mode: {{ user_files_sym_mode }}
  46. {% endif -%}
  47. {% if user_files_exclude_pat -%}
  48. - exclude_pat: "{{ user_files_exclude_pat }}"
  49. {% endif -%}
  50. - include_empty: True
  51. - keep_symlinks: True
  52. - require:
  53. - user: users_{{ username }}_user
  54. - file: users_{{ username }}_user
  55. {% endif -%}
  56. {%- endif -%}
  57. {%- endfor -%}