Saltstack Official Users Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

47 行
1.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. {%- 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 -%}