Saltstack Official Users Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 satır
2.6KB

  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_dir_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:dir_mode'), False) -%}
  13. {%- set user_files_sym_mode = salt['pillar.get'](('users:' ~ username ~ ':user_files:sym_mode'), False) -%}
  14. {%- set user_files_exclude_pat = salt['pillar.get'](('users:' ~ username ~ ':user_files:exclude_pat'), False) -%}
  15. {%- if user_files.enabled -%}
  16. {%- if user_files.source is defined -%}
  17. {%- if user_files.source.startswith('salt://') -%}
  18. {%- set file_source = user_files.source -%}
  19. {%- else -%}
  20. {%- set file_source = ('salt://' ~ user.user_files.source) -%}
  21. {%- endif -%}
  22. {%- set skip_user = False -%}
  23. {%- else -%}
  24. {%- if ('users/files/user/' ~ username) in userfile_dirs -%}
  25. {%- set file_source = ('salt://users/files/user/' ~ username) -%}
  26. {%- set skip_user = False -%}
  27. {%- else -%}
  28. {%- set skip_user = True -%}
  29. {%- endif -%}
  30. {%- endif -%}
  31. {%- if not skip_user %}
  32. users_userfiles_{{ username }}_recursive:
  33. file.recurse:
  34. - name: {{ user_home }}
  35. - source: {{ file_source }}
  36. - user: {{ username }}
  37. - group: {{ user_group }}
  38. {% if user_files_template -%}
  39. - template: {{ user_files_template }}
  40. {% endif -%}
  41. - clean: False
  42. {% if user_files_file_mode -%}
  43. - file_mode: {{ user_files_file_mode }}
  44. {% endif -%}
  45. {% if user_files_dir_mode -%}
  46. - dir_mode: {{ user_files_dir_mode }}
  47. {% endif -%}
  48. {% if user_files_sym_mode -%}
  49. - sym_mode: {{ user_files_sym_mode }}
  50. {% endif -%}
  51. {% if user_files_exclude_pat -%}
  52. - exclude_pat: "{{ user_files_exclude_pat }}"
  53. {% endif -%}
  54. - include_empty: True
  55. - keep_symlinks: True
  56. - require:
  57. - user: users_{{ username }}_user
  58. - file: users_{{ username }}_user
  59. {% endif -%}
  60. {%- endif -%}
  61. {%- endfor -%}