Saltstack Official Users Formula
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

user_files.sls 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. {%- if user_files.enabled -%}
  11. {%- if user_files.source is defined -%}
  12. {%- if user_files.source.startswith('salt://') -%}
  13. {%- set file_source = user_files.source -%}
  14. {%- else -%}
  15. {%- set file_source = ('salt://' ~ user.user_files.source) -%}
  16. {%- endif -%}
  17. {%- set skip_user = False -%}
  18. {%- else -%}
  19. {%- if ('users/files/user/' ~ username) in userfile_dirs -%}
  20. {%- set file_source = ('salt://users/files/user/' ~ username) -%}
  21. {%- set skip_user = False -%}
  22. {%- else -%}
  23. {%- set skip_user = True -%}
  24. {%- endif -%}
  25. {%- endif -%}
  26. {%- if not skip_user %}
  27. users_userfiles_{{ username }}_recursive:
  28. file.recurse:
  29. - name: {{ user_home }}
  30. - source: {{ file_source }}
  31. - user: {{ username }}
  32. - group: {{ user_group }}
  33. - clean: False
  34. - include_empty: True
  35. - keep_symlinks: True
  36. - require:
  37. - user: users_{{ username }}_user
  38. - file: users_{{ username }}_user
  39. {% endif -%}
  40. {%- endif -%}
  41. {%- endfor -%}